Android中自定义checkbox样式
2013-10-22 11:38
323 查看
1.首先在drawable文件夹中添加drawable文件checkbox_style.xml。
[html] view
plaincopy
<?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.在values文件夹下的styles.xml文件中添加CustomCheckboxTheme样式。
[html] view
plaincopy
<style name="CustomCheckboxTheme" parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/checkbox_style</item>
</style>
3.在布局文件中使用CustomCheckboxTheme样式。
[html] view
plaincopy
<CheckBox
android:id="@+id/select_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/CustomCheckboxTheme" />
使用到的图片资源
![](http://hi.csdn.net/attachment/201112/27/0_1324978367qQx1.gif)
checkbox_normal.png
![](http://hi.csdn.net/attachment/201112/27/0_1324978373H8U6.gif)
checkbox_pressed.png
[html] view
plaincopy
<?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.在values文件夹下的styles.xml文件中添加CustomCheckboxTheme样式。
[html] view
plaincopy
<style name="CustomCheckboxTheme" parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/checkbox_style</item>
</style>
3.在布局文件中使用CustomCheckboxTheme样式。
[html] view
plaincopy
<CheckBox
android:id="@+id/select_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/CustomCheckboxTheme" />
使用到的图片资源
![](http://hi.csdn.net/attachment/201112/27/0_1324978367qQx1.gif)
checkbox_normal.png
![](http://hi.csdn.net/attachment/201112/27/0_1324978373H8U6.gif)
checkbox_pressed.png
相关文章推荐
- android checkbox设置自定义的样式
- android中CheckBox自定义样式
- android CheckBox 自定义样式
- Android中自定义checkbox样式
- android UI学习 -- 设置界面的布局(包括style的使用,selector的使用,Checkbox自定义样式,菜单项的样式)
- xamarin android checkbox自定义样式
- Androidの自定义checkbox样式
- Android中自定义checkbox样式
- Android CheckBox自定义样式
- Android中自定义checkbox样式
- Android 自定义CheckBox样式
- Android中自定义checkbox样式
- Android中自定义checkbox样式
- android中checkbox自定义样式
- Android 自定义checkbox样式
- Android中自定义checkbox样式
- android中checkbox自定义样式
- Android Studio自定义CheckBox样式
- android UI学习 -- 设置界面的布局(包括style的使用,selector的使用,Checkbox自定义样式,菜单项的样式)
- Android自定义样式的Checkbox