It is actually very simple. There are three steps:
1. Create the file checkbox_selector.xml in drawable:
<? XML version = "1.0" encoding = "UTF-8"?> <Selector xmlns: Android = "http://schemas.android.com/apk/res/android"> <item Android: state_checked = "true" Android: drawable = "@ drawable/checkbox_ OK"/> <! -- Set the selected image --> <item Android: state_checked = "false" Android: drawable = "@ drawable/checkbox_empty"/> <! -- Set the unselected image --> </selector>
2. Create styles. XML in values:
<?xml version="1.0" encoding="utf-8"?><resources> <style name="MyCheckBox" parent="@android:style/Widget.CompoundButton.CheckBox"> <item name="android:button">@drawable/checkbox_selector</item> <item name="android:paddingLeft">25.0dip</item> <item name="android:maxHeight">10.0dip</item> </style></resources>
3. Add attributes to your checkbox:
<CheckBox android:id="@+id/check" android:layout_width="20dp" android:layout_height="20dp" android:layout_marginLeft="5dp" style="@style/MyCheckBox" />
Done! In this way, replace your checkbox with the two images you set.