I'm displaying a seekbar inside a fragment. The seekbar has custom thumb and progress drawables. They display fine, however when I pause the activity and return to it, the progress bar width strangely increases to the same height of the thumb ! I can't find the problem for this abnormal behavior.
my code :
// inside fragment onStart
seekBar.setThumb(getResources().getDrawable(R.drawable.form_bg));
seekBar.setProgressDrawable(getResources().getDrawable(R.drawable.progress));
// seekBar xml
<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:indeterminate="false"
android:layout_marginTop="5dp"
android:max="100"
android:maxHeight="6dp"
android:progress="50" />
// thumb drawable
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="oval"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<size android:height="@dimen/seekbar_tumb_size" android:width="@dimen/seekbar_tumb_size" />
<solid android:color="@color/form_color" />
</shape>
// progress drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="0dp" android:bottom="0dp" android:gravity="center_vertical" android:id="@android:id/background">
<shape>
<solid android:color="@color/activity_bg" />
</shape>
</item>
<item android:gravity="center_vertical" android:id="@android:id/progress">
<clip>
<shape>
<solid android:color="@color/form_color_syrup" />
</shape>
</clip>
</item>
Finally found the solution to this.
Rect bounds = seekBar.getProgressDrawable().getBounds();
seekBar.setThumb(getResources().getDrawable(R.drawable.form_bg));
seekBar.setProgressDrawable(getResources().getDrawable(R.drawable.progress));
seekBar.getProgressDrawable().setBounds(bounds);