Change progressbar color through CODE ONLY in Android

hico picture hico · Jun 8, 2012 · Viewed 63.3k times · Source

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.

Answer

Mit Bhatt picture Mit Bhatt · Feb 25, 2013

This will help much no need to do so much coding :)

ProgressBar spinner = new android.widget.ProgressBar(
            context,
            null,
            android.R.attr.progressBarStyle);

spinner.getIndeterminateDrawable().setColorFilter(0xFFFF0000,android.graphics.PorterDuff.Mode.MULTIPLY);