1、首先res/drawable中定義編寫如下樣式:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/check_true" android:state_checked="true"></item> <item android:drawable="@drawable/check_true" android:state_selected="true"></item> <item android:drawable="@drawable/check_true" android:state_pressed="true"></item> <item android:drawable="@drawable/check_false"></item> </selector>
2、在layout中添加checkbox控件:
<CheckBox android:id="@+id/radioButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/btn_check" android:button="@null" android:checked="true"/>
其中drwable/btn_check為1中頂一個文件名稱,另外必須將android:button設置為@null。
@drawable/check_true和@drawable/check_false為checkbox不同狀態的圖片,可自行設計。