@Composable
fun SliderWithCustomTrackAndThumb() {
var sliderPosition by remember { mutableStateOf(0f) }
val interactionSource = MutableInteractionSource()
val colors = SliderDefaults.colors(thumbColor = Color.Red, activeTrackColor = Color.Red)
Column {
Text(text = sliderPosition.toString())
Slider(
modifier = Modifier.semantics { contentDescription = "Localized Description" },
value = sliderPosition,
onValueChange = { sliderPosition = it },
valueRange = 0f..100f,
onValueChangeFinished = {
// launch some business logic update with the state you hold
// viewModel.updateSelectedSliderValue(sliderPosition)
},
interactionSource = interactionSource,
thumb = {
SliderDefaults.Thumb(
interactionSource = interactionSource,
colors = colors
)
},
track = { sliderPositions ->
SliderDefaults.Track(
colors = colors,
sliderPositions = sliderPositions
)
}
)
}
}
The above composable function creates a sample slider with a custom thumb size. I want to increase the size of the track. how can I do that?
You can increase or decrease the size of the track and thumb using scale modifiers. This is how I do it:
screenshot