您的位置:首页 > 移动开发 > Android开发

Android中Selsetor基本使用三,选中时改变CheckBox背景

2016-06-17 14:22 477 查看
效果图

未选中



选中



activity_main.xml文件中

<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.zhh.demo.MainActivity">
<CheckBox
android:id="@+id/cb"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="测试背景的改变"
android:paddingLeft="10dp"
android:textSize="18sp"
android:button="@drawable/checkbox_style"
/>
</LinearLayout></span>
背景选择器,选中,未选中换两张图片就好了

checkbox_style.xml

<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@mipmap/chex_on" android:state_checked="true"/>
<item android:drawable="@mipmap/chex_nm" android:state_checked="false"/>
<item android:drawable="@mipmap/chex_nm"/>
</selector></span>


源码下载:

http://download.csdn.net/detail/zhaihaohao1/9552539
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: