androidx.compose.material3

RangeSlider

Composable function

One of the slider types. It works like Slider. Only the parameters that differ are described here.

A slider with two thumbs that picks a range, like a price from 20 to 80.

Pick a range with two thumbs
Pick a range with two thumbs
var price by remember { mutableStateOf(20f..60f) }
Column(Modifier.width(280.dp)) {
    Text("€${price.start.roundToInt()} – €${price.endInclusive.roundToInt()}")
    RangeSlider(value = price, onValueChange = { price = it }, valueRange = 0f..100f)
}

Basic

Takes value and onValueChange.

@Composable
fun RangeSlider(
    value: ClosedFloatingPointRange<Float>,
    onValueChange: (ClosedFloatingPointRange<Float>) -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    valueRange: ClosedFloatingPointRange<Float> = 0f..1f,
    steps: Int = 0,
    onValueChangeFinished: (() -> Unit)? = null,
    colors: SliderColors = SliderDefaults.colors(),
)

value: ClosedFloatingPointRange<Float>Required

The current value. Pass your state here. For a RangeSlider, a range like 20f..60f.

onValueChange: (ClosedFloatingPointRange<Float>) -> UnitRequired

Called with the new value while the user drags. Update your state here.

Same as in Slider: modifier, enabled, valueRange, steps, onValueChangeFinished, colors.

Custom thumb and track

Like basic, plus thumb and track to draw your own.

@Composable
fun RangeSlider(
    value: ClosedFloatingPointRange<Float>,
    onValueChange: (ClosedFloatingPointRange<Float>) -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    valueRange: ClosedFloatingPointRange<Float> = 0f..1f,
    onValueChangeFinished: (() -> Unit)? = null,
    colors: SliderColors = SliderDefaults.colors(),
    startInteractionSource: MutableInteractionSource = remember { MutableInteractionSource() },
    endInteractionSource: MutableInteractionSource = remember { MutableInteractionSource() },
    startThumb: @Composable (RangeSliderState) -> Unit = { SliderDefaults.Thumb(interactionSource = startInteractionSource, colors = colors, enabled = enabled) },
    endThumb: @Composable (RangeSliderState) -> Unit = { SliderDefaults.Thumb(interactionSource = endInteractionSource, colors = colors, enabled = enabled) },
    track: @Composable (RangeSliderState) -> Unit = { rangeSliderState -> SliderDefaults.Track(colors = colors, enabled = enabled, rangeSliderState = rangeSliderState) },
    steps: Int = 0,
)

startInteractionSource: MutableInteractionSourceOptional

Default: remember { MutableInteractionSource() }

The interaction source of the start thumb of a RangeSlider.

endInteractionSource: MutableInteractionSourceOptional

Default: remember { MutableInteractionSource() }

The interaction source of the end thumb of a RangeSlider.

startThumb: @Composable (RangeSliderState) -> UnitOptional

Default: { SliderDefaults.Thumb(interactionSource = startInteractionSource, colors = colors, enabled = enabled) }

Draws the start thumb of a RangeSlider.

endThumb: @Composable (RangeSliderState) -> UnitOptional

Default: { SliderDefaults.Thumb(interactionSource = endInteractionSource, colors = colors, enabled = enabled) }

Draws the end thumb of a RangeSlider.

track: @Composable (RangeSliderState) -> UnitOptional

Default: { rangeSliderState -> SliderDefaults.Track(colors = colors, enabled = enabled, rangeSliderState = rangeSliderState) }

Draws the track. Default: SliderDefaults.Track.

Same as above: value, onValueChange.

Same as in Slider: modifier, enabled, valueRange, onValueChangeFinished, colors, steps.

State

Takes a SliderState that holds the value.

@Composable
fun RangeSlider(
    state: RangeSliderState,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    colors: SliderColors = SliderDefaults.colors(),
    startInteractionSource: MutableInteractionSource = remember { MutableInteractionSource() },
    endInteractionSource: MutableInteractionSource = remember { MutableInteractionSource() },
    startThumb: @Composable (RangeSliderState) -> Unit = { SliderDefaults.Thumb(interactionSource = startInteractionSource, colors = colors, enabled = enabled) },
    endThumb: @Composable (RangeSliderState) -> Unit = { SliderDefaults.Thumb(interactionSource = endInteractionSource, colors = colors, enabled = enabled) },
    track: @Composable (RangeSliderState) -> Unit = { rangeSliderState -> SliderDefaults.Track(colors = colors, enabled = enabled, rangeSliderState = rangeSliderState) },
)

state: RangeSliderStateRequired

Holds the value, range and steps. Create it with remember { SliderState(value = 0.5f) }.

Same as in Slider: modifier, enabled, colors.

Same as above: startInteractionSource, endInteractionSource, startThumb, endThumb, track.

Slider types

See also