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" />