[ Web Proxy ]
URL:
Viewing: https://developer.android.com/develop/ui/compose/components/slider [Back]  [Original]

Slider  |  Jetpack Compose  |  Android Developers Skip to main content
Essentials Design & Plan Develop Google Play Blog
Search:
Android Studio
Android Developers [Android Developers]

Slider Stay organized with collections Save and categorize content based on your preferences.

The Slider composable allows users to make selections from a range of values. You might use a slider to let the user do the following:

The slider contains a track, thumb, value label, and tick marks:

A slider with thumb, track and tick marks. [A slider with thumb, track and tick marks.] Figure 1. An implementation of a slider.

Basic implementation

See the Slider reference for a full API definition. Some of the key parameters for the Slider composable are the following:

The following example is a straightforward slider. It allows the user to select a value from 0.0 to 1.0. Because the user can select any value in that range, the slider is continuous.

@Preview
@Composable
fun SliderMinimalExample() {
    var sliderPosition by remember { mutableFloatStateOf(0f) }
    Column {
        Slider(
            value = sliderPosition,
            onValueChange = { sliderPosition = it }
        )
        Text(text = sliderPosition.toString())
    }
}

This implementation appears as follows:

A slider component with a value selected roughly three quarters along the track. [A slider component with a value selected roughly three quarters along the track.] Figure 2. A basic implementation of a slider.

Advanced implementation

When implementing a more complex slider, you can additionally make use of the following parameters.

The following snippet implements a slider that has three steps, with a range from 0.0 to 50.0. Because the thumb snaps to each step, this slider is discrete.

@Preview
@Composable
fun SliderAdvancedExample() {
    var sliderPosition by remember { mutableFloatStateOf(0f) }
    Column {
        Slider(
            value = sliderPosition,
            onValueChange = { sliderPosition = it },
            colors = SliderDefaults.colors(
                thumbColor = MaterialTheme.colorScheme.secondary,
                activeTrackColor = MaterialTheme.colorScheme.secondary,
                inactiveTrackColor = MaterialTheme.colorScheme.secondaryContainer,
            ),
            steps = 3,
            valueRange = 0f..50f
        )
        Text(text = sliderPosition.toString())
    }
}

The implementation appears as follows:

A discrete slider with a range from 0 to 50, showing five tick marks at equal intervals. The thumb is positioned near the second tick mark, indicating a selected value of 16. [A discrete slider with a range from 0 to 50, showing five tick marks at equal intervals. The thumb is positioned near the second tick mark, indicating a selected value of 16.] Figure 3. A slider with steps and a set value range. Note: The very beginning and end of a slider count as "steps". In the preceding example where the range is 0f..50f and the number of steps is 3, each interval along the range is 12.5 because the beginning and end of the slider are also intervals the user can select.Note: You can also pass Slider a thumb and track composable to more thoroughly customize the appearance of the component.

Range slider

You can also use the dedicated RangeSlider composable. This allows the user to select two values. This can be useful in cases such as when the user wishes to select a minimum and maximum price.

The following example is a relatively straightforward example of a continuous range slider.

@Preview
@Composable
fun RangeSliderExample() {
    var sliderPosition by remember { mutableStateOf(0f..100f) }
    Column {
        RangeSlider(
            value = sliderPosition,
            steps = 5,
            onValueChange = { range -> sliderPosition = range },
            valueRange = 0f..100f,
            onValueChangeFinished = {
                // launch some business logic update with the state you hold
                // viewModel.updateSelectedSliderValue(sliderPosition)
            },
        )
        Text(text = sliderPosition.toString())
    }
}

A range slider component with two values selected. A label displays the upper and lower bounds of the selection. [A range slider component with two values selected. A label displays the upper and lower bounds of the selection.] Figure 4. An implementation of a range slider.

Additional resources

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2026-08-14 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-08-14 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page