先上图:
选中状态: 未选中状态:
以下是代码:
1、在layout中正常用checkbox标签,改变style属性
<CheckBox
android:id="@+id/my_checkbox"
style="@style/DeviceCheckbox"
android:layout_width="30dp"
android:layout_height="wrap_content" />
2、styles.xml中添加
<style name="DeviceCheckbox" parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/btn_check_selector</item>
<item name="android:paddingLeft">25dip</item>
<item name="android:maxHeight">30dip</item>
</style>
3、btn_check_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_checked" android:state_checked="true" />
<item android:drawable="@drawable/ic_checked" android:state_selected="true" />
<item android:drawable="@drawable/ic_checked" android:state_pressed="true" />
<item android:drawable="@drawable/ic_uncheck"></item>
</selector>
完成