I have implemented a simple SeekBar whose thumb gets large while the user touches it. While this works fine in Marshmallow devices, it doesn't on Lollipop.
In Marshmallow- (This is how it should be)
On touch-
The two problems are-
- The thumb is no longer vertically centered.
- The progress doesn't visibly change while the user is touching the thumb.
Here is my activity layout-
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false">
<SeekBar
android:id="@+id/seekBar_main_green"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginTop="20dp"
android:max="255"
android:thumb="@drawable/custom_thumb_green" />
</RelativeLayout>
</ScrollView>
Here is my class-
sbGreen.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// Changing background color of some other view
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
sbGreen.setThumb(ContextCompat.getDrawable(MainActivity.this, R.drawable.custom_thumb_green_large));
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
sbGreen.setThumb(ContextCompat.getDrawable(MainActivity.this, R.drawable.custom_thumb_green));
}
});
Here are my drawables-
custom_thumb-
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" >
<shape android:shape="oval">
<size
android:width="10dp"
android:height="10dp" />
<solid android:color="#00af00" />
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="#50008000"/>
<size android:height="20dp" android:width="20dp"/>
</shape>
</item>
</layer-list>
custom_thumb_large-
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="30dp"
android:left="30dp"
android:right="30dp"
android:top="30dp" >
<shape android:shape="oval">
<size
android:width="10dp"
android:height="10dp" />
<solid android:color="#00af00" />
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="#50008000"/>
<size android:height="40dp" android:width="40dp"/>
</shape>
</item>
</layer-list>
Things I have tried-
Set
maxHeight
to large value as mentioned here- stackoverflow- how to fix seekbar bar thumb centering issuesSet
minHeight
andmaxHeight
equal or less thanlayout_height
as mentioned above and here- stackoverflow- custom seekbar thumb vertical position issueLooked here but I am not using any custom progress drawable- stackoverflow- android marshmallow custom seekbar progress bar not showing
Any help or suggestions are most welcome.