Androidの自定义checkbox样式
2015-06-11 09:30
211 查看
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实现gif图与文字混排
- android POST请求
- android 文件读取(assets)
- android实现gif图与文字混排
- Android的布局方式
- Android高手进阶教程(二十一)之---Android中创建与几种解析xml的方法!
- Android之Service&BroadCastReceiver
- ubuntu如何完全卸载和安装 Java及android环境
- Android:Layout_weight的深刻理解
- Android开发环境搭建
- Android事件机制完全解析
- 详解android:scaleType属性
- java4Android(6)函数的复写(override)/对象的转型(向上转型/向下转型)
- android 时间戳与日期格式的互相转换 以及 自定义选择器
- Android学习十二:跑马灯程序实现(简单联系)
- Mac OS X下开发Android用手机调试
- Android Canvas绘图详解(图文)
- android全屏去掉title栏的多种实现方法
- Android 数据库
- android Activity四种启动模式