自定义样式的checkBox
2016-04-06 01:07
387 查看
我们都喜欢有自己的风格,那设置checkBox的样式也很简单。
直接切入主题吧!
(1)在res/drawable下新建checkbox_style.xml--->自己命名
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/check_switch_on"
android:state_checked="true"></item>
<item android:drawable="@drawable/check_switch_on"
android:state_selected="true"></item>
<item android:drawable="@drawable/check_switch_on"
android:state_pressed="true"></item>
<item android:drawable="@drawable/check_switch_off" ></item>
</selector>
红色部分就是用于判断控件的状态;
绿色部分用于不同状态对应的图片;
紫色部分则表示默认情况下显示什么图片。
(2)完成(1)后就将设置checkBox的两个属性就可以了:
<CheckBox
android:id="@+id/app_check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@null"
android:background="@drawable/checkbox_style"
android:focusable="false"/>
运行效果就出来了,什么样的风格自己定义哈。
直接切入主题吧!
(1)在res/drawable下新建checkbox_style.xml--->自己命名
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/check_switch_on"
android:state_checked="true"></item>
<item android:drawable="@drawable/check_switch_on"
android:state_selected="true"></item>
<item android:drawable="@drawable/check_switch_on"
android:state_pressed="true"></item>
<item android:drawable="@drawable/check_switch_off" ></item>
</selector>
红色部分就是用于判断控件的状态;
绿色部分用于不同状态对应的图片;
紫色部分则表示默认情况下显示什么图片。
(2)完成(1)后就将设置checkBox的两个属性就可以了:
<CheckBox
android:id="@+id/app_check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@null"
android:background="@drawable/checkbox_style"
android:focusable="false"/>
运行效果就出来了,什么样的风格自己定义哈。
相关文章推荐