自定义Button样式相同,新建Android XML文件,类型选Drawable,根结点选selector,在这定义具体的样式。

123456789
<?xml version="1.0" encoding="UTF-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:state_checked="true" android:state_pressed="true"android:drawable="@drawable/focused" /><item android:state_checked="false" android:state_pressed="true"android:drawable="@drawable/normal" /><item android:state_checked="false" android:drawable="@drawable/normal" /><item android:state_checked="true" android:drawable="@drawable/focused" /></selector>


state_checked 选中状态 state_pressed按下状态
即分别设置checkbox选中和没选中时,按下和没按下时显示的图片.
应用到Checkbox与Button不同,并不是设置Background属性,而是设置style属性,所以我们要写一个style。
在strings.xml写一个style,

123
<style name="MyCheckBox" parent="@android:style/Widget.CompoundButton.CheckBox"><item name="android:button">@drawable/checkbox</item></style>

应用到Checkbox:

1234
<CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content"style="@style/MyCheckBox"/>

更多相关文章

  1. 关于 Android(安卓)4.4 系统屏幕旋转调研
  2. Android(安卓)Http请求框架二:xUtils 框架网络请求
  3. Android(安卓)Studio制作简易计算器源代码及详解
  4. 8.1.2 Android中的13种Drawable小结 Part 2
  5. 设置Android默认锁定屏幕旋转
  6. EditText常用属性
  7. 关于CoordinatorLayout展开与折叠相关属性
  8. Android自定义滚动条(ScrollBar)样式
  9. 安卓模拟器设置网速和延迟

随机推荐

  1. 关于android 1.6全部的权限介绍
  2. QMUI android 框架 git下载项目运行报错
  3. Android(安卓)新的锁屏接口的实现
  4. 编译android 7.0 出现Try increasing hea
  5. android 开源组件合集-UI篇(2013-11-07更
  6. android 源码开发 关于编译等小知识点总
  7. android emulator创建avd命令
  8. Android(安卓)4.0 wifi 和 Ethernet 的实
  9. Android(安卓)Adb指令
  10. android onGestureListener的方法