我必须在我的工作中自定义复选框图像,最后我在how-to-change-default-images-of-checkbox找到了解决方案,它通过使用'android:button'属性很好用,但给我留下了另一个问题,复选框'android:button'属性已应用,难以检查和取消选中。
以下是Checkbox的选择器:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/gn_checkbox_checked" android:state_checked="true"/>
<item android:drawable="@drawable/gn_checkbox_normal" android:state_checked="false"/>
<item android:drawable="@drawable/gn_checkbox_normal"/>
</selector>
使用此选择器的复选框:
<CheckBox
android:id="@+id/timeline_check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/checkbox"
android:layout_marginRight="3dp" />
注意:没有'android:button'属性,复选框很容易检查和取消选中,有没有一种优雅的方法来解决这个问题?非常感谢。