Android自定义CheckBox样式
2015-12-08 10:30
357 查看
Android提供了CheckBox控件,但是样式单一。例如,当背景为白色时,系统提供的Checkbox样式会让CheckBox隐藏在白色背景中。这时,我们需要用我们自己的资源图片自定义CheckBox样式。
效果如下:
1.在drawable文件夹中添加drawable文件hide_checkbox_style.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/hide_apps_checked" android:state_checked="true"/> <item android:drawable="@drawable/hide_apps_unchecked" android:state_checked="false"/> <item android:drawable="@drawable/hide_apps_unchecked"/> </selector>
2.在values文件夹下的style.xml文件中添加HideCheckboxTheme样式
<style name="HideCheckboxTheme" parent="@android:style/Widget.CompoundButton.CheckBox"> <item name="android:button">@drawable/hide_checkbox_style</item> </style>
3.在CheckBox中使用HideCheckboxTheme样式
<CheckBox android:id="@+id/app_hide" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="10dp" style="@style/HideCheckboxTheme" android:layout 4000 _alignParentRight="true" android:layout_centerVertical="true" />
效果如下:
相关文章推荐
- android 取消AsyncTask继续运行的解决方案
- androidstudio项目目录详解
- android ndk
- android(43)(调用系统照相机功能)
- armeabi-v7a armeabi arm64-v8a
- Android获取包名的方法
- android AudioManager类介绍
- Android ListView无数据视图
- android surport
- Android NDK 和 OpenCV 整合开发总结
- 一个优秀的Android应用从建项目开始
- Android 缓存框架 ASimpleCache
- android keystore文件转换格式为pk8和x509.pem
- Android Studio:中文注释乱码错误解决办法
- 在OpenCV for Android 2.4.5中使用SURF(nonfree module)
- Android:进程间通信交互
- Android Root插件模式:Xposed源码剖析
- 自定义控件之-手势锁
- Android 获得View的宽和高
- android 设置壁纸,开启出现短暂黑屏问题