美文网首页
简单设置checkbox

简单设置checkbox

作者: shuaikun | 来源:发表于2017-09-11 19:05 被阅读6次

首先引入两张图片checked、normal
然后我们设置一个背景选择器checkbox_style.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/checked" android:state_checked="true"/>
    <item android:drawable="@drawable/normal" android:state_checked="false"/>
    <item android:drawable="@drawable/normal"/>

</selector>

在设置checkbox的时候直接将其button设置为他就行了

<CheckBox
             android:id="@+id/checkbox1"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="@strings/check_text"
             android:button="@drawable/checkbox_style"
             android:checked="true"/>

相关文章

网友评论

      本文标题:简单设置checkbox

      本文链接:https://www.haomeiwen.com/subject/djmfsxtx.html