First, add the following custom style to the Styles.xml:
- <style name= "MyCheckBox" parent= "@android: Style/widget.compoundbutton.checkbox" >
- <item name= "Android:button" > @drawable/my_checkbox</item>
- </style>
Copy Code
The contents of the My_checkbox.xml are:
- <?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_pressed"/>
- <item android:state_checked= "false" android:drawable= "@drawable/checkbox"/>
- <item android:drawable= "@drawable/checkbox"/>
- </selector>
Copy Code
Code snippets that use custom styles:
- <checkbox
- Android:id= "@+id/checked"
- Android:layout_alignparentright= "true"
- android:layout_marginright= "10dip"
- Android:layout_centervertical= "true"
- Android:layout_width= "40dip"
- android:layout_height= "Wrap_content"
- Android:checked= "false"
- style= "@style/mycheckbox"
- />
Copy Code
Add two photos checkbox_pressed.png, checkbox.png
http://www.eoeandroid.com/forum.php?mod=viewthread&tid=148630
[Android instance] changing the style of a checkbox