1. First add the drawable file Checkbox_style.xml in the Drawable folder.
[HTML]View Plaincopyprint?
- <? XML version= "1.0" encoding="Utf-8"?>
- <selector xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:drawable= "@drawable/checkbox_pressed" android:state_checked="true"/ >
- <item android:drawable= "@drawable/checkbox_normal" android:state_checked="false" />
- <item android:drawable="@drawable/checkbox_normal"/>
- </selector>
<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android "> <item android:drawable=" @drawable/checkbox_pressed "android:state_checked=" true "/> <item android:drawable= "@drawable/checkbox_normal" android:state_checked= "false"/> <item android: drawable= "@drawable/checkbox_normal"/></selector>
2. Add the Customcheckboxtheme style to the Styles.xml file under the Values folder.
[HTML]View Plaincopyprint?
- <style name= "Customcheckboxtheme" Parent= "@android: Style/widget.compoundbutton.checkbox" >
- <item name= "Android:button" > @drawable/checkbox_style </item>
- </style>
<style name= "Customcheckboxtheme" parent= "@android: Style/widget.compoundbutton.checkbox" ><item name= " Android:button "> @drawable/checkbox_style</item></style>
3. Use the Customcheckboxtheme style in the layout file.
[HTML]View Plaincopyprint?
- <CHECKBOX&NBSP;&NBSP;
- android:id= "@+id/select_all" &NBSP;&NBSP;
- android:layout_width= "Wrap_ Content "&NBSP;&NBSP;
- android:layout_height= "wrap_content" &NBSP;&NBSP;
- style=< Span class= "Attribute-value" > "@style/customcheckboxtheme" />&NBSP;&NBSP;
<checkbox android:id= "@+id/select_all" android:layout_width= "wrap_content" android:layout_ height= "Wrap_content" style= "@style/customcheckboxtheme"/>
Picture resources to use
Checkbox_normal.png
Checkbox_pressed.png
Customize checkbox style in Android