自定义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. EditText常用属性
  2. android 修改actionbar title文字颜色等属性
  3. 获取android顶部状态栏高度的两种方式
  4. Android,TextView的所有属性和方法
  5. EditText的属性!

随机推荐

  1. xp一体机文件永久删除怎么找到
  2. VMware Workstation Linux 安装及桥接网
  3. 盲盒源码h5|数码盲盒源码开发搭建
  4. 插画要怎么构图?插画绘制构图技巧
  5. 人体躯干到底怎么画?超基础的人体躯干画法
  6. 哪些人适合学HTML5?
  7. web前端必备技术有哪些?
  8. Linux安装MySQL(使用yum)
  9. Android(安卓)Studio error: Unable to s
  10. android实现开机自启动服务