我需要以编程方式设置辅助进度条颜色。
我只看到方法
ProgressBar.setProgressDrawable(drawable)
用于设置主色,但没有设置副色的方法。
我该怎么做?
最佳答案
ProgressBar.getProgressDrawable()
返回一个 LayerDrawable
,其中:
LayerDrawable progressDrawable = (LayerDrawable) getProgressDrawable();
Drawable backgroundColor = progressDrawable.getDrawable(0);
Drawable secondaryColor = progressDrawable.getDrawable(1);
Drawable primaryColor = progressDrawable.getDrawable(2);
我尝试修改颜色(示例):
progressDrawable.setDrawableByLayerId(progressDrawable.getId(2), new ClipDrawable(...));
但有时画面卡住,有时死机。 最后我因为时间不够而放弃了寻找。 对不起:(
米歇尔
关于安卓进度条 : how to set secondary color programmatically,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6235890/