I want to have a thumb for both min and max for my seekbar. You should be able to drag both thumbs independently.
Seekbar where I can change both min max value with 2 thumbs
10.6k Views Asked by user1564762 At
2
There are 2 best solutions below
0
On
The normal seekbar in android can't have two thumbs that can be changed.
Instead use Slider from the Material Compoments Library. https://material.io/components/sliders/#
Dependencies we need to include is:
implementation 'com.google.android.material:material:1.2.0-alpha05'
Example layout to test this slider
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.android.material.slider.Slider
android:id="@+id/slider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:value="12.34"
android:valueFrom="0.0"
android:valueTo="50.0" />
<com.google.android.material.slider.Slider
android:id="@+id/rangeSlider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:valueFrom="0.0"
android:valueTo="100.0" />
</LinearLayout>
In your activity set up the range slider with two thumbs:
Slider rangeSlider = findViewById(R.id.rangeSlider);
rangeSlider.setValues(0.0F, rangeSlider.getMaximumValue());
In your styles.xml change from AppCompat to MaterialComponents, like this:
From: parent="Theme.AppCompat.Light.DarkActionBar">
To: parent="Theme.MaterialComponents.Light.DarkActionBar">

Just use the
RangeSliderin Material Components and the methodsetValues()with:
You can also use:
with
res/values/arrays.xml:Note: This requires a minimum of version 1.2.0-beta01