Tuesday, 1 September 2015

android change progress bar color programmatically



http://developer.android.com/intl/zh-cn/reference/android/widget/ProgressBar.html



As amfcosta mentioned here:

http://stackoverflow.com/questions/5745814/android-change-horizonal-progress-bar-color

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