CheckBox自定义

<CheckBox
        android:id="@+id/account_checkBox_agree"
        android:layout_width="140dip"
        android:layout_height="wrap_content"
        android:button="@drawable/checkbox"
        android:text="已阅读并同意"
        android:textColor="#024089"
        android:textSize="15sp"
        android:checked="true"
        android:singleLine="true"
        android:layout_toLeftOf="@id/account_agreement_link"
        android:layout_alignBottom="@id/account_agreement_link"
        android:layout_centerVertical="true"
        ></CheckBox>

 

checkbox.xml 在drawable目录下

 

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

    <item android:state_checked="true" android:state_focused="true"
        android:drawable="@drawable/checkbox_on_background_focus_yellow" />
       
    <item android:state_checked="false" android:state_focused="true"
        android:drawable="@drawable/checkbox_off_background_focus_yellow" />
       
    <item android:state_checked="false" android:state_focused="false"
        android:drawable="@drawable/checkbox_off_background" />
   
    <item android:state_checked="true" android:state_focused="false"
        android:drawable="@drawable/checkbox_on_background" /> 
   
</selector>

之后再添加需要的效果图片即可

你可能感兴趣的:(xml,android)