首先引入兩張圖片checked、normal
然后我們?cè)O(shè)置一個(gè)背景選擇器checkbox_style.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/checked" android:state_checked="true"/>
<item android:drawable="@drawable/normal" android:state_checked="false"/>
<item android:drawable="@drawable/normal"/>
</selector>
在設(shè)置checkbox的時(shí)候直接將其button設(shè)置為他就行了
<CheckBox
android:id="@+id/checkbox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@strings/check_text"
android:button="@drawable/checkbox_style"
android:checked="true"/>