How to change progress bar progress color?
Solution 1
If android version is 5.0 and above you just need to set
android:indeterminateTint="@color/BLACK"
android:indeterminateTintMode="src_in"
For lower version I use this
mProgressBar.getIndeterminateDrawable().setColorFilter(getResources()
.getColor(R.color.primary_color),PorterDuff.Mode.SRC_IN);
Solution 2
Create a new XML file in your drawable folder called something like custom_progress_bar.xml
and paste this there:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Define the background properties like color etc -->
<item android:id="@android:id/background">
<clip>
<shape>
<solid android:color="#000000" />
</shape>
</clip>
</item>
<!-- Define the progress properties like start color, end color etc -->
<item android:id="@android:id/progress">
<clip>
<shape>
<solid android:color="#FFFFFF" />
</shape>
</clip>
</item>
</layer-list>
And in your <ProgressBar>
add this attribute:
android:progressDrawable="@drawable/custom_progress_bar"
Change the 2 colors to your own preference. I put #FFFFFF
and #000000
which are white and black.
Solution 3
Go to your styles.xml and change the colorAccent value from your base application theme e.g.
<item name="colorAccent">{COLOR}</item>
I am using minSdkVersion 15 and it worked for me.
Solution 4
If you want to change the ProgressBar color, not by drawable, you can use this style as theme for the ProgressBar
<style name="ProgressBar" parent="Widget.AppCompat.ProgressBar">
<item name="colorAccent">@color/white_primary</item>
</style>
Solution 5
Try this and add you custom color
Progressbar mBar= (ProgressBar) findViewById(R.id.spinner);
mBar.getIndeterminateDrawable().setColorFilter(Color.parseColor("#80DAEB"),
android.graphics.PorterDuff.Mode.MULTIPLY);
Hope this helps
AmateurProgrammer
I am a computer science major at hte University of Arizona. I plan on working on the software development side of things both for PC and Mobile.
Updated on July 17, 2022Comments
-
AmateurProgrammer almost 2 years
I created this progress bar for my app, but I cant get that yellow orangy color that appears to change to something like red or blue.
<ProgressBar android:id="@+id/progress_bar" style="@android:style/Widget.ProgressBar.Horizontal" android:layout_width="250sp" android:layout_height="wrap_content" android:progress="2" android:layout_marginTop="82dp" android:max="3" android:indeterminate="false" android:layout_below="@+id/imageView" android:layout_centerHorizontal="true" />
above is my progress bar xml code.
Any help guys? :)
Thanks so much in advance! :)
-
AmateurProgrammer almost 8 yearsDear Vuko, Your method worked amazingly! Thanks for your help! :)
-
Navjot over 6 yearsI want to do the same programmatically. In my case, I want to change the progress color from code using hex value without changing the background color. Need help.
-
Vucko over 6 yearsWhat comes to my mind is that you can create the same drawable with a different color, and replace the progress drawable from code. If you need to dynamically choose the color (it ain't always the same), then it's harder, If I think of a solution I'll let you know :D @NavjotBedi
-
Vucko about 5 yearsThis is only a good solution if you don't mind that EVERYWHERE your colors might change to this.
ColorAccent
is a very important attribute and should be changed with caution. Check this -
Vucko about 5 yearsIt might look easier than my solution to add just this one line people, but it come with some caveats. Beware before using it.