1

I use this method to change SeekBar's thumb color:

  public static void setThumbColor(final SeekBar sb, @ColorInt final int color) {
    final Drawable thumb = sb.getThumb();
    thumb.setColorFilter(color, PorterDuff.Mode.SRC_IN);
    sb.setThumb(thumb);
  }

and this code works well on Android 5.0 (Lollipop) and newer. But on Android 4.2.2 or 4.3.1 my method doesn't work, color of thumb doesn't change.

What should I do to change color of thumb on older android versions?

P. Ilyin
  • 761
  • 10
  • 28

2 Answers2

2

Create a new style in style.XML

<style name="SeekBarColor"
parent="Widget.AppCompat.SeekBar"> 
<item name="colorAccent">@color/your_color</item> 
</style>

Finally in the layout

  <SeekBar
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:theme="@style/SeekBarColor" />
Abhi
  • 3,431
  • 1
  • 17
  • 35
0

Try this one,

sb.getProgressDrawable().setColorFilter(getResources().getCo‌​lor(R.color.my_color‌​), PorterDuff.Mode.SRC_ATOP);

or

sb.getProgressDrawable().setColorFilter(0xFF00FF00, PorterDuff.Mode.MULTIPLY);
sb.getThumb().setColorFilter(0xFF00FF00, PorterDuff.Mode.MULTIPLY);
Prokash Sarkar
  • 11,723
  • 1
  • 37
  • 50