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:
Android 4.4:
Android 5.0.1, 5.1, 5.1.1:
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