Android 自定義checkbox圖片過大問題

首先我們新建一個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里的圖片大小便得到了修改。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容