android之修改CheckBox左侧图标样式

     很多时候系统自带的CheckBox样式并不能满足我们的需求,本文讲解如何替换CheckBox选中,未选中状态下的左侧图片背景的替换。

     1.在res目录下创建drawable文件夹,在drawable创建my_checkbox.xml文件

        my_checkbox.xml文件内容如下:

              <selector xmlns:android="http://schemas.android.com/apk/res/android">

                   //未选中状态  my_normal为未选中状态图片                 

                  <item android:state_checked="false" android:drawable="@drawable/my_normal" />  

                   //选中状态    my_selector为选中状态图片 
                  <item android:state_checked="true" android:drawable="@drawable/my_selector" /> 
            </selector> 

     2.设置CheckBox   

        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/my_checkbox"
            android:button="@null"/>  

    

原文地址:https://www.cnblogs.com/zyppac/p/3575172.html