开发者

android how to change the progressbar color programatically

How can you change the progressbar color from within the app. I already have it set in the XML but as the value gets within preset thresholds I need to change the color of the bar to alert the user. For the buttons I can set it like the example below. Is there a way to do with with the progressbar?

B.setBackgroundDrawable(c.getResour开发者_高级运维ces().getDrawable(R.drawable.button2));
B.getBackground().setColorFilter( UserS.ColorBtnBack, PorterDuff.Mode.MULTIPLY);


I posted a tip as a comment on your other question, see http://colintmiller.com/2010/10/07/how-to-add-text-over-a-progress-bar-on-android/

Scroll down to "Bonus Tip", which discusses changing color. I guess you want a predefined set of colors, which you could then switch between using setProgressDrawable()


ProgressBar uses a LevelListDrawable with setProgressDrawable() to determine the color of the bar. You can try assembling a LevelListDrawable in Java, though I have never tried that -- I have only defined them via XML.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜