android之修改CheckBox左侧图标样式
? ? ?很多時候系統自帶的CheckBox樣式并不能滿足我們的需求,本文講解如何替換CheckBox選中,未選中狀態下的左側圖片背景的替換。
? ? ?1.在res目錄下創建drawable文件夾,在drawable創建my_checkbox.xml文件
? ? ? ? my_checkbox.xml文件內容如下:
? ? ? ? ? ? ? <selector xmlns:android="http://schemas.android.com/apk/res/android">
? ? ? ? ? ? ? ? ? ?//未選中狀態 ?my_normal為未選中狀態圖片? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? <item android:state_checked="false" android:drawable="@drawable/my_normal" /> ?
? ? ? ? ? ? ? ? ? ?//選中狀態 ? ?my_selector為選中狀態圖片?
? ? ? ? ? ? ? ? ? <item android:state_checked="true" android:drawable="@drawable/my_selector" />?
? ? ? ? ? ? </selector>?
?
? ? ?2.設置CheckBox? ?
? ? ? ? <CheckBox
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:background="@drawable/my_checkbox"
? ? ? ? ? ? android:button="@null"/> ?
? ??
轉載于:https://www.cnblogs.com/zyppac/p/3575172.html
總結
以上是生活随笔為你收集整理的android之修改CheckBox左侧图标样式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 文本框获取和失去焦点默认值问题
- 下一篇: Analyzer报表结果行