Lollipop Progress Bar Tinting

I’m on a Lollipop device (MotoG 2014), I read about progress bar tinting, but this is not working…I get the default progress bar color. What am I missing here?

<ProgressBar
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:backgroundTintMode="src_in"
    android:indeterminate="true"
    android:indeterminateTint="#f00" />

Many thanks.

  • Android: Making changes to a button's parent view
  • Preview ViewSwitcher in AndroidStudio
  • Recommend a Java / Android Game Library - card, board, etc.?
  • Is it preferable to use Activity.onAttachFragment or Fragment.onAttach to communicate between an Activity and a nested fragment?
  • Android Studio recognizes physical Device as Null?
  • How to prevent multiple instances of an activity when it is launched with different intents
  • Show soft keyboard for dialog
  • Test events were not received - Android Studio
  • How to align the text inside the TextView in Android?
  • Android - Understanding View.getLocalVisibleRect(Rect)
  • How to make RelativeSizeSpan align to top
  • Using JAXB with Google Android
  • 2 Solutions collect form web for “Lollipop Progress Bar Tinting”

    Try changing your ProgressBar to this

    <ProgressBar
    android:id="@+id/view_progress"
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:indeterminate="true"
    android:indeterminateTintMode="src_in"
    android:indeterminateTint="@color/red"
    />
    

    Also you can do it programmaticaly doing this :

    ProgressBar progressBar;
    progressBar = (ProgressBar)findViewById(R.id.view_progress);
    progressBar.getProgressDrawable().setColorFilter(Color.RED, Mode.SRC_IN);
    

    References

    Setting in ProgressBar Tint color

    The accepted solution wasn’t working for me on pre-Lollipop, but I found this solution to fit all APIs and on top of that, it doesn’t use any deprecated code:

    // fixes pre-Lollipop progressBar indeterminateDrawable tinting
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
    
        Drawable wrapDrawable = DrawableCompat.wrap(mProgressBar.getIndeterminateDrawable());
        DrawableCompat.setTint(wrapDrawable, ContextCompat.getColor(getContext(), android.R.color.holo_green_light));
        mProgressBar.setIndeterminateDrawable(DrawableCompat.unwrap(wrapDrawable));
    } else {
        mProgressBar.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(getContext(), android.R.color.holo_green_light), PorterDuff.Mode.SRC_IN);
    }
    

    Happy coding !

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.