android中自定义checkbox的图片和大小

其实很简单,分三步:

1.在drawable中创建文件checkbox_selector.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_ok" /><!--设置选中图片-->
	<item android:state_checked="false" 
 		android:drawable="@drawable/checkbox_empty" /><!--设置未选中图片-->
</selector>


2. 在values中创建styles.xml:

 

 

<?xml version="1.0" encoding="utf-8"?>

<resources>

  	<style name="MyCheckBox" parent="@android:style/Widget.CompoundButton.CheckBox">

  	 <item name="android:button">@drawable/checkbox_selector</item>

  	 <item name="android:paddingLeft">25.0dip</item>

  	 <item name="android:maxHeight">10.0dip</item>

  	</style>

</resources>


3. 在你的CheckBox中添加属性:

 

 

<CheckBox
        android:id="@+id/check"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_marginLeft="5dp"
        style="@style/MyCheckBox"  
        />


搞定!这样就把你的checkbox换成你设置的那两张图片了

 

 

posted @ 2013-07-25 19:08  jlins  阅读(21869)  评论(0编辑  收藏  举报