0

I've been trying to tint the ProgressBar drawable for an app with support till API 15. I need to do it dynamically as well. Here's what I have tried so far:

XML:

<ProgressBar
    android:id="@+id/progressBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:indeterminate="true" />

Java:

    Drawable drawable = DrawableCompat.wrap(progressBarSync.getIndeterminateDrawable());
    DrawableCompat.setTint(drawable, colorVibrantDark);

OUTPUT:

Android 6:

enter image description here

Android 4.4:

enter image description here

Android 5.0.1, 5.1, 5.1.1:

enter image description here

Problems:

  • Android 5: ProgressBar is not visible on devices running Lollipop. (It may be white, not visible on white background! Nope it is not visible at all.)
  • Android 4.0-4.4:This code runs inside a ViewPager. So changing the page changes the tint of the drawable.

What else have I tried ? (Developers sometimes can go crazy when things don't work as expected!! :) )

    // wrap using DrawableCompat
    Drawable drawable = DrawableCompat.wrap(progressBarSync.getIndeterminateDrawable());
    // don't wrap using DrawableCompat :/
    Drawable indeterminateDrawable = progressBarSync.getIndeterminateDrawable();
    // set the tint for wrapped drawable
    DrawableCompat.setTint(drawable, colorVibrantDark);
    // change the color filter as well for the wrapped drawable
    drawable.setColorFilter(colorVibrantDark,
            PorterDuff.Mode.SRC_IN);
    // set the tint for the NOT wrapped drawable
    DrawableCompat.setTint(indeterminateDrawable, colorVibrantDark);
    // change the color filter as well for the NOT wrapped drawable        
    indeterminateDrawable.setColorFilter(colorVibrantDark,
            PorterDuff.Mode.SRC_IN);

Any help/suggestion is appreciated.

Thanks

Ankit Popli
  • 2,809
  • 3
  • 37
  • 61
  • 1
    This might help http://stackoverflow.com/questions/27567235/certain-progressbar-styles-not-shown-on-nexus-5-android-5-0-1 – Shubham May 14 '16 at 05:48
  • @Shubham Thanks a ton buddy. This [answer](http://stackoverflow.com/a/28674548/1796173) worked for me. Please consider answering it here as well. – Ankit Popli May 23 '16 at 07:18

0 Answers0