在Android中实现自定义checkbox样式
2016-01-08 16:10
435 查看
1.首先在drawable文件夹中添加drawable文件checkbox_style.xml。
<?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样式。
<style name="CustomCheckboxTheme" parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/checkbox_style</item>
</style>
3.在布局文件中使用CustomCheckboxTheme样式。
<CheckBox
android:id="@+id/select_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/CustomCheckboxTheme" />
4.用到的图片见下面:
<?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样式。
<style name="CustomCheckboxTheme" parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/checkbox_style</item>
</style>
3.在布局文件中使用CustomCheckboxTheme样式。
<CheckBox
android:id="@+id/select_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/CustomCheckboxTheme" />
4.用到的图片见下面:
相关文章推荐
- Android实现TextView两端对齐的方法
- Android_通过Bugtags平台,方便测试人员提交bug及整个bug系统的管理
- Android开发--通过相册或拍照选择头像
- Android系统权限配置详解
- Fragment初学7——Fragment在Android开发中的应用1
- Android中<meta-data>的使用
- 找不到android-support-v4.jar、android-support-v7.jar怎么办?
- Android版的股票行情K线图开发
- Android结构及Framework启动流程
- 在Android Studio中使用NDK
- android studio中导入百度自动更新SDK
- android——打电话(直接拨号or跳转到打电话界面)
- Crazy Android Note Chapter-13
- Android Fragment详解(四):管理Fragment
- Android高手进阶:Adapter深入理解与优化
- android连接蓝牙打印机实现打印功能
- Android 自定义Toast
- 关于Android EditText密码显示隐藏切换
- 如何实现android手机摄像头的的自动对焦
- Android SDK在线更新镜像服务器