We just launched Compose Examples featuring over 150+ components! Check it out →

InlineSlider

Android

Component in Wear Material Compose

[InlineSlider] allows users to make a selection from a range of values. The range of selections is shown as a bar between the minimum and maximum values of the range, from which users may select a single value. InlineSlider is ideal for adjusting settings such as volume or brightness.

Value can be increased and decreased by clicking on the increase and decrease buttons, located accordingly to the start and end of the control. Buttons can have custom icons - [decreaseIcon] and [increaseIcon].

The bar in the middle of control can have separators if [segmented] flag is set to true. A single step value is calculated as the difference between min and max values of [valueRange] divided by [steps] + 1 value.

Last updated:

Installation

dependencies {
   implementation("androidx.wear.compose:compose-material:1.5.0-alpha03")
}

Overloads

@Composable
fun InlineSlider(
    value: Float,
    onValueChange: (Float) -> Unit,
    steps: Int,
    decreaseIcon: @Composable () -> Unit,
    increaseIcon: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    valueRange: ClosedFloatingPointRange<Float> = 0f..(steps + 1).toFloat(),
    segmented: Boolean = steps {'<='} 8,
    colors: InlineSliderColors = InlineSliderDefaults.colors(),
)

Parameters

namedescription
valueCurrent value of the Slider. If outside of [valueRange] provided, value will be coerced to this range.
onValueChangeLambda in which value should be updated
stepsSpecifies the number of discrete values, excluding min and max values, evenly distributed across the whole value range. Must not be negative. If 0, slider will have only min and max values and no steps in between
decreaseIconA slot for an icon which is placed on the decrease (start) button
increaseIconA slot for an icon which is placed on the increase (end) button
modifierModifiers for the Slider layout
enabledControls the enabled state of the slider. When false, this slider will not be clickable
valueRangeRange of values that Slider value can take. Passed [value] will be coerced to this range
segmentedA boolean value which specifies whether a bar will be split into segments or not. Recommendation is while using this flag do not have more than 8 [steps] as it might affect user experience. By default true if number of [steps] is {'<='}8.
colors[InlineSliderColors] that will be used to resolve the background and content color for this slider in different states
@Composable
fun InlineSlider(
    value: Int,
    onValueChange: (Int) -> Unit,
    valueProgression: IntProgression,
    decreaseIcon: @Composable () -> Unit,
    increaseIcon: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    segmented: Boolean = valueProgression.stepsNumber() {'<='} 8,
    colors: InlineSliderColors = InlineSliderDefaults.colors(),
)

Parameters

namedescription
valueCurrent value of the Slider. If outside of [valueProgression] provided, value will be coerced to this range.
onValueChangeLambda in which value should be updated
valueProgressionProgression of values that Slider value can take. Consists of rangeStart, rangeEnd and step. Range will be equally divided by step size
decreaseIconA slot for an icon which is placed on the decrease (start) button
increaseIconA slot for an icon which is placed on the increase (end) button
modifierModifiers for the Slider layout
enabledControls the enabled state of the slider. When false, this slider will not be clickable
segmentedA boolean value which specifies whether a bar will be split into segments or not. Recommendation is while using this flag do not have more than 8 steps as it might affect user experience. By default true if number of steps is {'<='}8.
colors[InlineSliderColors] that will be used to resolve the background and content color for this slider in different states

Code Examples

InlineSliderSample

@Composable
fun InlineSliderSample() {
    var value by remember { mutableStateOf(4.5f) }
    InlineSlider(
        value = value,
        onValueChange = { value = it },
        increaseIcon = { Icon(InlineSliderDefaults.Increase, "Increase") },
        decreaseIcon = { Icon(InlineSliderDefaults.Decrease, "Decrease") },
        valueRange = 3f..6f,
        steps = 5,
        segmented = false
    )
}

InlineSliderSegmentedSample

@Composable
fun InlineSliderSegmentedSample() {
    var value by remember { mutableStateOf(2f) }
    InlineSlider(
        value = value,
        onValueChange = { value = it },
        increaseIcon = { Icon(InlineSliderDefaults.Increase, "Increase") },
        decreaseIcon = { Icon(InlineSliderDefaults.Decrease, "Decrease") },
        valueRange = 1f..4f,
        steps = 7,
        segmented = true
    )
}

InlineSliderWithIntegerSample

@Composable
fun InlineSliderWithIntegerSample() {
    var value by remember { mutableStateOf(4) }
    InlineSlider(
        value = value,
        onValueChange = { value = it },
        increaseIcon = { Icon(InlineSliderDefaults.Increase, "Increase") },
        decreaseIcon = { Icon(InlineSliderDefaults.Decrease, "Decrease") },
        valueProgression = 0..10,
        segmented = false
    )
}
by @alexstyl