Android中自定义checkbox样式
2015-06-03 16:15
441 查看
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" />
使用到的图片资源
checkbox_normal.png
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" />
使用到的图片资源
checkbox_normal.png
checkbox_pressed.png
相关文章推荐
- Android fill_parent、wrap_content和match_parent的区别
- 兼容 Android 4.4 透明状态栏与导航栏
- Android自定义组合标题控件
- Android——SlidingMenu学习总结
- Android ViewPager+Fragment 仿 Google Play 带箭头的导航栏
- Android学习笔记(五)基于监听的事件模式和基于回调的事件模式
- android中getSystemService详解
- android Singleton
- Android:使用ZXing生成二维码(支持添加Logo图案)
- 社会化分享组建(一)
- android 布局
- Android中Handler引起的内存泄露
- Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用
- Android开发中的Json字符串与复杂的嵌套对象互转。
- Fresco: android上的图像处理库
- Android 如何使用shape绘制只有一个圆角的矩形
- Android 自动化测试—robotium(十一) robotium实现微博绑定
- Android任务和返回栈完全解析,细数那些你所不知道的细节
- 转载:Android自动化测试- 自动获取短信验证码
- Android开发规范