Android中自定义checkbox样式
2015-12-02 14:14
495 查看
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中的布局和控件
- Android Selector用法
- android 打开浏览器指定网页
- Android IOS WebRTC 音视频开发总结(五四)-- WebRTC标准之父谈WebRTC
- Android集成Facebook sdk,Key Hashes生成步骤
- android屏幕适配(二)
- 加快Android构建速度
- Android动画_TranslateAnimation
- android Studio常用快捷键
- android适配(一)
- 关于android.support.v7.widget.RecyclerView包导入项目引发的BUG
- android 按两次物理返回键退出程序
- Android触摸屏幕事件总结
- Android6.0的phone应用源码分析(1)——智能手机的硬件结构介绍
- Android Material Design之Toolbar与Palette实践
- android studio开发环境配置(指定SDK及卸载)附安装文件网盘地址(win7 64位)
- Android下setLatestEventInfo警告、Handler警告、SimpleDateFormat警告
- Android开发随手记
- 关于Android中传递数据的一些讨论--备用
- android popwindow 位置和动画