首先我們新建一個drawable,屬性是selector,設(shè)置倆張圖片,用以checked時切換圖片。
xml version="1.0"encoding="utf-8"?><selector?xmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:drawable="@drawable/companion_open"android:state_checked="true">item><itemandroid:drawable="@drawable/companion_close"android:state_checked="false">item></selector>
然后定義一個style,CheckBox_style
<style?name="wrist_light_screen_checkbox"parent="@android:style/Widget.CompoundButton.CheckBox">
<itemname="android:button">@nullitem><itemname="android:background">@drawable/checkbox_selectoritem>
</style>
注意parent所指定的style,以及item 的button,background的屬性設(shè)定。
最后,在布局文件里使用CheckBox即可
<CheckBox?android:id="@+id/cb_switch"
android:layout_width="45dp"
android:layout_height="45dp"
style="@style/wrist_light_screen_checkbox"/>
這樣,CheckBox里的圖片大小便得到了修改。