標籤:
1.首先在drawable檔案夾中添加drawable檔案checkbox_style.xml。<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/checkbox_pressed" android:state_checked="true"/> <item android:drawable="@drawable/checkbox_normal" android:state_checked="false"/> <item android:drawable="@drawable/checkbox_normal"/></selector>2.在values檔案夾下的styles.xml檔案中添加CustomCheckboxTheme樣式。<style name="CustomCheckboxTheme" parent="@android:style/Widget.CompoundButton.CheckBox"> <item name="android:button">@drawable/checkbox_style</item></style>3.在布局檔案中使用CustomCheckboxTheme樣式。<CheckBox android:id="@+id/select_all" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/CustomCheckboxTheme" />
使用到的圖片資源
checkbox_normal.png
checkbox_pressed.png
Android中自訂checkbox樣式