android 自定义checkbox大小跟图片[已验证]

android 自定义checkbox大小和图片[已验证]

 

 <CheckBox
        android:id="@+id/checkBox"
        style="@style/mystyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginRight="15dp"
        android:focusable="false" >
    </CheckBox>

 

 

 

mycheck_selection.xml

 

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:state_checked="true" 
    android:drawable="@drawable/checkbox_tick" /><!--选中时效果-->
 <item android:state_checked="false" 
   android:drawable="@drawable/checkbox" /><!--未选中时效果-->
  <!-- 修改成你自己的图片就可以了 -->
</selector>

 

 

 

style.xml

 

 

<?xml version="1.0" encoding="utf-8"?>
<resources>
       <style name="mystyle" parent="@android:style/Widget.CompoundButton.CheckBox">
    <item name="android:button">@drawable/mycheck_selection</item>
    <item name="android:paddingLeft">25.0dip</item>
    <item name="android:maxHeight">10.0dip</item>
   </style>
</resources>