Slider

fun Slider(state: SliderState, modifier: Modifier = Modifier, enabled: Boolean = true, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, valueRange: ClosedFloatingPointRange<Float> = 0f..1f, orientation: Orientation = Orientation.Horizontal, track: @Composable () -> Unit, thumb: @Composable () -> Unit)

A foundational component used to build sliders.

For interactive preview & code examples, visit Slider Documentation.

Basic Example

val sliderState = rememberSliderState(initialValue = 0.5f)

Slider(
state = sliderState,
track = {
Box(
modifier = Modifier
.fillMaxWidth()
.height(4.dp)
.background(Color.Gray)
)
},
thumb = {
Box(
modifier = Modifier
.size(24.dp)
.background(Color.Blue, CircleShape)
)
}
)

Parameters

state

The SliderState that controls the slider.

modifier

Modifier to be applied to the slider.

enabled

Whether the slider is enabled.

interactionSource

The MutableInteractionSource that will be used to dispatch drag events.

valueRange

The range of values that the slider can take.

orientation

The orientation of the slider.

track

The composable that represents the track of the slider.

thumb

The composable that represents the thumb of the slider.