0

I've set progress bar tint in XML, but it isn't working on API 21 (Android 5.0)

    <ProgressBar
        android:layout_width="match_parent"
        android:layout_height="5dp"
        style="@android:style/Widget.ProgressBar.Horizontal"
        android:progressTint="@color/blue"/>

The tint is the default yellow colour on API 21, but is correctly blue on API 22 and above.

According to the docs, the corresponding set method setProgressTintList was introduced in API 21, so I don't understand why this doesn't work. (My minimum API version is 21 so I don't need to worry about lower versions.)

Adam Burley
  • 5,551
  • 4
  • 51
  • 72

1 Answers1

0

you can do it with xml like this (Work on API 21+):

<ProgressBar
            android:layout_width="match_parent"
            android:layout_height="5dp"
            style="@android:style/Widget.ProgressBar.Horizontal"
            android:progressTint="@color/blue"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:layout_marginTop="50dp"
            android:layout_marginBottom="50dp"
            android:indeterminate="true"
            android:indeterminateTintMode="src_atop"
            android:indeterminateTint="@color/blue">

and with Java:

Drawable progressDrawable = yourProgressBar.getProgressDrawable().mutate();
progressDrawable.setColorFilter(Color.RED, 
android.graphics.PorterDuff.Mode.SRC_IN);
yourProgressBar.setProgressDrawable(progressDrawable);

and for you case API 21 seting a progress tint with java should also work:

yourProgressBar.setProgressTintList(ColorStateList.valueOf(Color.RED));

or

yourProgressBar.getProgressDrawable().setColorFilter(
    Color.RED, android.graphics.PorterDuff.Mode.SRC_IN);

hope it helps.

Rohit Bhati
  • 371
  • 2
  • 11
  • But I'm not trying to create an indeterminate progress bar, I'm trying to create a determinate one...and I'm also trying to do this in XML – Adam Burley Aug 12 '22 at 12:57