我有 android 绘图,我将应用到几个 TextView 的背景
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
<item android:id="@+id/clr"
android:left="0.5dp" android:right="0.5dp" android:top="0.5dp" android:bottom="0.5dp" >
<shape android:shape="rectangle">
<solid android:color="#FFF000" />
</shape>
</item>
</layer-list>
我想以编程方式改变它的颜色。我怎样才能做到这一点?
可以这样做
// "cellLabel" background colour of textview or button etc.
LayerDrawable layers = (LayerDrawable) cellLabel.getBackground();
// drawable item id
GradientDrawable shape = (GradientDrawable) (layers.findDrawableByLayerId(R.id.clr));
shape.setColor(my_color);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)