Tuesday, 1 September 2015

android change progress bar color programmatically


As amfcosta mentioned here:


ProgressBar progressbar = (ProgressBar) findViewById(R.id.progressbar);
int color = 0xFF00FF00;
progressbar.getIndeterminateDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
progressbar.getProgressDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);

This code works.

But I don't know what "getIndeterminateDrawable()" for. because without this line the code still works.

One more color can be changed is the background color:

Above picture shows the color set by "getProgressDrawable().setColorFilter()"

The green color shows on the above picture is the background color.

No comments:

Post a comment