I have set Horizontal Progress bar.
I would like to change progress color of yellow.
<ProgressBar
android:id="@+id/progressbar"
android:layout_width="80dip"
android:layout_height="20dip"
android:focusable="false"
style="?android:attr/progressBarStyleHorizontal" />
The problem is, the progress color is different in different devices. So, I want it to fix the progress color.
For anyone looking for how to do it programmatically:
Setting ids to drawables is crucial, and takes care of preserving bounds and actual state of progress bar
If you only want to change the progress bar color, you can simply use a color filter in your Activity's onCreate() method:
Idea from here.
You only need to do this for pre-lollipop versions. On Lollipop you can use the colorAccent style attribute.
I copied this from one of my apps, so there's prob a few extra attributes, but should give you the idea. This is from the layout that has the progress bar:
Then create a new drawable with something similar to the following (In this case greenprogress.xml):
You can change up the colors as needed, this will give you a green progress bar.
The simplest solution I found out is something like this:
Put the above in
styles.xml
file underres > values
folder.NOTE: If you use any other accent color, then the previous solutions should be good to go with.
API 21 or HIGHER
above answers change the whole background color and it's ambigios that it change the height of progress bar to very max.which unable to change in xml. better way to change only progress bar status that how much is completed i.s 20% red color, 50% yellow color 70% and above green color. you can do it programmatically in java.
share your answer if you have any other solution.
A simpler solution:
progess_drawable_blue