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

<?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,

<?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>

应用到Checkbox:

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

更多相关文章

  1. 在Android(安卓)Studio上进行OpenCV3.1开发环境的配置
  2. 按钮的多样话 selector的使用
  3. 【Android(安卓)应用开发】GitHub 优秀的 Android(安卓)开源项目
  4. Android(安卓)禁止横竖屏切换
  5. android的软键盘的enter键的替换
  6. android根据字体大小设置控件高度
  7. TextView、EditText属性简介
  8. android light
  9. 【Android(安卓)应用开发】GitHub 优秀的 Android(安卓)开源项目

随机推荐

  1. Android安全机制详解
  2. Android系统启动,用过安卓手机的都知道,你
  3. Android占领2010的六大理由
  4. android 添加文件打开方式,找了很久终于找
  5. android layout以及一些常用的android控
  6. Permissions
  7. Android Layout XML属性研究--android:la
  8. 【转载】【Android】Android Camera 使用
  9. Android实现使用流媒体播放远程mp3文件的
  10. android 中 焦点控制