Slider

fun Slider(value: Float, onValueChange: (Float) -> Unit, modifier: Modifier = Modifier, enabled: Boolean = true, valueRange: ClosedFloatingPointRange<Float> = 0f..1f, keyStep: Float = (valueRange.endInclusive - valueRange.start) / 100f, keyRepeatStep: Float = keyStep, onValueChangeFinished: () -> Unit? = null, colors: SliderColors = SliderDefaults.colors(), interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, thumb: @Composable (SliderState) -> Unit = { SliderDefaults.Thumb( interactionSource = interactionSource, colors = colors, enabled = enabled, ) }, track: @Composable (SliderState) -> Unit = { sliderState -> SliderDefaults.Track(sliderState = sliderState, colors = colors, enabled = enabled) })(source)

Displays a focusable slider controlled by D-pad keys.

A single Left or Right press changes the value by keyStep. Holding a key changes it by keyRepeatStep for each repeat.

Parameters

value

the current slider value, constrained to valueRange

onValueChange

called with each value change

modifier

the Modifier to be applied to this slider

enabled

whether the slider responds to user input

valueRange

the range of values available to the slider

keyStep

the value change for a single Left or Right press

keyRepeatStep

the value change for each key repeat while Left or Right is held

onValueChangeFinished

called on key-up, when focus is lost, or when the slider is disabled

colors

the colors used for enabled and disabled states. See SliderDefaults.colors.

interactionSource

the MutableInteractionSource used to observe focus interactions

thumb

the thumb slot, which receives the current SliderState

track

the track slot, which receives the current SliderState


fun Slider(state: SliderState, onValueChange: (Float) -> Unit, modifier: Modifier = Modifier, enabled: Boolean = true, keyStep: Float = (state.valueRange.endInclusive - state.valueRange.start) / 100f, keyRepeatStep: Float = keyStep, onValueChangeFinished: () -> Unit? = null, colors: SliderColors = SliderDefaults.colors(), interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, thumb: @Composable (SliderState) -> Unit = { SliderDefaults.Thumb( interactionSource = interactionSource, colors = colors, enabled = enabled, ) }, track: @Composable (SliderState) -> Unit = { sliderState -> SliderDefaults.Track(sliderState = sliderState, colors = colors, enabled = enabled) })(source)

Displays a slider backed by state and controlled by D-pad keys.

A single Left or Right press changes the value by keyStep. Holding a key changes it by keyRepeatStep for each repeat.

Parameters

state

the SliderState that holds the slider value and range

onValueChange

called with each value change

modifier

the Modifier to be applied to this slider

enabled

whether the slider responds to user input

keyStep

the value change for a single Left or Right press

keyRepeatStep

the value change for each key repeat while Left or Right is held

onValueChangeFinished

called on key-up, when focus is lost, or when the slider is disabled

colors

the colors used for enabled and disabled states. See SliderDefaults.colors.

interactionSource

the MutableInteractionSource used to observe focus interactions

thumb

the thumb slot, which receives the current SliderState

track

the track slot, which receives the current SliderState