androidandroid-seekbarmaterial-components-androidrangeseekbarandroid-slider

Seekbar where I can change both min max value with 2 thumbs


I want to have a thumb for both min and max for my seekbar. You should be able to drag both thumbs independently.


Solution

  • Just use the RangeSlider in Material Components and the method setValues()

        <com.google.android.material.slider.RangeSlider
            android:id="@+id/slider"            
            android:valueFrom="0"
            android:valueTo="10"
            ../>
    

    with:

    RangeSlider slider = findViewById(R.id.slider);
    slider.setValues(1.0f,5.0f);
    

    enter image description here

    You can also use:

        <com.google.android.material.slider.RangeSlider
            android:id="@+id/slider"            
            android:valueFrom="0"
            android:valueTo="10"
            app:values="@array/initial_slider_values"
            ../>
    

    with res/values/arrays.xml:

    <resources>
      <array name="initial_slider_values">
        <item>1.0</item>
        <item>5.0</item>
      </array>
    </resources>
    

    Note: This requires a minimum of version 1.2.0-beta01