[Android实例] 更改CheckBox的样式
首先在styles.xml添加如下的自定义样式:
- <style name="mycheckbox" parent="@android:style/Widget.CompoundButton.CheckBox">
 - <item name="android:button">@drawable/my_checkbox</item>
 - </style>
 
my_checkbox.xml的内容为:
- <?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>
 
使用自定义样式的代码段:
- <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"
 - />
 
添加两张图片checkbox_pressed.png、checkbox.png
http://www.eoeandroid.com/forum.php?mod=viewthread&tid=148630
                    
                
                
            
        
浙公网安备 33010602011771号