是否可以从 res-colors.xml 更改颜色:
<color name="transparent_color">#00000000</color>
在运行时?
更改它的原因是,在我扩展的 EditText 上,我将 backgroundresouce 设置为:
setBackgroundResource(R.drawable.edittext_rounded_corners);
edittext_rounded_corners.xml 看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/edittext_rounded_corners.xml -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="true"><shape>
<solid android:color="#FF8000" />
<stroke android:width="2.3dp" android:color="@color/referenceFrame" />
<corners android:radius="8dp" />
</shape></item>
<item android:state_focused="false" android:state_pressed="true"><shape>
<solid android:color="#FF8000" />
<stroke android:width="2.3dp" android:color="#FF8000" />
<corners android:radius="8dp" />
</shape></item>
<item android:state_focused="true" android:state_pressed="false"><shape>
<solid android:color="#FFFFFF" />
<stroke android:width="2.3dp" android:color="#FF8000" />
<corners android:radius="8dp" />
</shape></item>
<item android:state_focused="false" android:state_pressed="false"><shape>
<gradient android:angle="270" android:centerColor="#FFFFFF" android:endColor="#FFFFFF" android:startColor="#F2F2F2" />
<stroke android:width="0.7dp" android:color="#BDBDBD" />
<corners android:radius="8dp" />
</shape></item>
<item android:state_enabled="true"><shape>
<padding android:bottom="4dp" android:left="4dp" android:right="4dp" android:top="4dp" />
</shape></item>
</selector>
当我有错误时,我需要一种方法使@Color/referenceFrame 变为红色。已经完成错误处理,只需要改变参考框架的方法