I have a progressBar using the ProgressBar class.
Just doing this:
progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);
I need to change the color of that one, using input value like so:
int color = "red in RGB value".progressBar.setColor(color)
or something like that...
I can't use an XML layout because the progress bar is customizable for users.
It is possible to colorize the Progress bar by setting the color filter on the progress bar drawable:
progressbar.setIndeterminateTintList(ColorStateList.valueOf(Color.RED));
It only works above API 21
This will help much no need to do so much coding :)
As I found help on a topic here but can't remember the link, I'm posting my full solution which works great for my needs:
And here is the code to convert DECIMAL color values to HEXADECIMAL:
I think the last method is not that clean but it works well.
Hope this well help, too much time wasted on this progressbar.
In the case that you need to tint the background and the progress bar in different colors.
progress_drawable.xml
Its possible, programmatically, to decompound its layer-list items, and tint them separately:
Update
In newer versions of Android (21 works), you can change the color of a progressbar programmatically by just using
setProgressTintList
.To set it red, use: