[英]Android Seekbar Progress Color at runtime
I want to change the seekbar progress color and background color at runtime with code not with xml. 我想在运行时使用不使用xml的代码更改搜索条进度颜色和背景颜色。 I know how to do it with xml
(Layerlist-Shapedrawable-Clipdrawable)
I can't change the colors in my colors.xml
so I have to set the progress drawable by code. 我知道如何使用xml
(Layerlist-Shapedrawable-Clipdrawable)
我无法更改colors.xml
的颜色,因此我必须通过代码设置可绘制的进度。 I already tried different things with LayerDrawable etc... but didn't get anything to work. 我已经尝试过使用LayerDrawable等不同的东西......但是没有任何工作。 Any ideas?
有任何想法吗?
public void setProgressBarColor(ProgressBar progressBar, int newColor){
LayerDrawable ld = (LayerDrawable) progressBar.getProgressDrawable();
ClipDrawable d1 = (ClipDrawable) ld.findDrawableByLayerId(R.id.progressshape);
d1.setColorFilter(newColor, PorterDuff.Mode.SRC_IN);
}
When you update the progress, you will see the result. 更新进度时,您将看到结果。
Is it ok? 好吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.