当复选框被选中时,我希望更改文本的颜色。目前我的代码如下:
<CheckBox
android:id="@+id/checkbox"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="@drawable/states"
android:gravity="center_horizontal|center_vertical"
android:button="@null"
android:text="test/>
当复选框被选中时,通常会改变其背景颜色。问题在于文本始终是相同的颜色。当复选框被选中时,如何改变文本颜色?
这是我用于更改复选框背景状态的方法(出于简单起见,我删除了其他内容):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false">
<layer-list >
<item>
<shape android:shape="oval">
</shape>
</item>
</layer-list>
</item>
<item android:state_checked="true" >
<layer-list >
<item>
<shape android:shape="oval">
</shape>
</item>
</layer-list >
</item>
</selector>