Android中自定义Checkbox

custom_checkbox.xml文件:

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

    <item android:drawable="@drawable/btn_unselect" android:state_checked="false"/>
    <item android:drawable="@drawable/btn_select" android:state_checked="true"/>

</selector>

styles.xml中

    <style name="custom_checkbox" parent="@android:style/Widget.CompoundButton.CheckBox">
        <item name="android:button">@drawable/custom_checkbox</item>
    </style>

Checkbox:

   <CheckBox  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:checked="true"
        android:text="全(不)选"
        android:layout_margin="10dip"
        android:paddingLeft="10dip"
        android:textSize="20sp"
        style="@style/custom_checkbox"
        android:textColor="@color/black"/> 

备注:

paddingLeft为左边的图标与右边的文字之间的距离
原文地址:https://www.cnblogs.com/xiaoxian1369/p/4156385.html