java将可绘制形状的颜色更改为给定的十六进制
我有以编程方式创建的textView。它们需要有不同的颜色值。我不需要动画或任何花哨的东西,只需将给定的十六进制值(例如FF00AB)应用于textView的可绘制形状:
列出项目。xml
<TextView
安卓:id="@+id/icon"
安卓:background="@drawable/rounded_corner" />
圆角。xml
<shape xmlns:安卓="http://schemas.安卓.com/apk/res/安卓" >
<solid 安卓:color="@color/dummyColorValue" />
</shape>
列表适配器。java
// Set Icon Color
String color "FF00AB";
Drawable iconDrawable = txtIcon.getBackground();
// how to change the <solid 安卓:color>-Value of iconDrawable HERE??
假设变量颜色的十六进制值是动态的
Q:setColorFilter()是错误的方法还是我必须转换字符串
# 1 楼答案
我提出的解决方案很少,它肯定会帮助您找到其中一个:
1
2
3
4
希望它能帮助你:)