How to change default color of progress bar?

Viewed 69928

I am using a circular ProgressBar in my Activty.My Problem is this it is not visible properly on my page because my page's BG color is same as ProgressBar .So how can I change the color of ProgressBar to make it properly Visible? Please Help

14 Answers

Go to the declaration of the progress bar in your .xml file :


And paste this line of code :

android:indeterminateTint="@color/white"

The example above allows you to change the color of your progress bar to white. Now it's up to you to adapt it to the color you want.

Only for Android API >= 21

for me, these two lines had to be there for it to work and change the color:

android:indeterminateTint="@color/yourColor"
android:indeterminateTintMode="src_in"

PS: but its only available from android 21

create progress drawable file

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@android:id/background">
    <shape>
        <corners android:radius="5dip" />
        <solid android:color="@color/colorWhite" />
    </shape>
</item>

<item android:id="@android:id/secondaryProgress">
    <clip>
        <shape>
            <corners android:radius="5dip" />
            <solid android:color="@color/colorPrimary" />
        </shape>
    </clip>
</item>

<item android:id="@android:id/progress">
    <clip>
        <shape>
            <corners
                android:radius="5dip" />
            <solid android:color="@color/colorPrimary" />
        </shape>
    </clip>
</item>

and set android:progressDrawable="@drawable/app_progressbar_back"

like this

<ProgressBar
                android:id="@+id/dialogProgressView"
                style="?android:attr/progressBarStyleHorizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:progressDrawable="@drawable/app_progressbar_back"
                android:progress="50"
                android:layout_marginTop="@dimen/margin_20" />

I'm using android 2.3.1 version. I create a xml file called progressbar and call it in the layout progress bar tag android:progressDrawable="@drawable/progressbar"

<item android:id="@+id/progress">
    <clip>
    <shape>
        <gradient android:startColor="@color/textColor"
            android:centerColor="@color/textColor"
            android:endColor="@color/textColor"
            android:gradientRadius="20dp"
            >
        </gradient>
    </shape>
    </clip>
</item>

The Chirag's answer is right, but not all.
I think the XML file should look like this:

<ProgressBar
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:indeterminateDrawable="@drawable/progress"/>
Related