其实很简单,分三步:

1.在drawable中创建文件checkbox_selector.xml:

 

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:andro>
	<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:
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_marginLeft="5dp"
        style="@style/MyCheckBox"  
        />


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

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-13
  • 2022-02-12
  • 2021-10-30
  • 2021-06-27
  • 2022-12-23
猜你喜欢
  • 2021-11-02
  • 2022-12-23
  • 2022-12-23
  • 2022-01-25
  • 2022-12-23
相关资源
相似解决方案