- 在drawable中創(chuàng)建selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@mipmap/check" />
<item android:state_checked="false" android:drawable="@mipmap/uncheck" />
<item android:drawable="@mipmap/uncheck" />
</selector>
- 在values文件夾下的styles.xml文件中添加CustomCheckboxTheme樣式筋遭。
<style name="CustomCheckBoxTheme" parent="Widget.AppCompat.CompoundButton.CheckBox">
<item name="android:button">@drawable/check_box_selector</item>
</style>
說(shuō)明
- 在drawable中引用mipmap的問(wèn)題
mipmaps 是一種可視化技術(shù)渲染算法屯掖,速度相當(dāng)快,所以google強(qiáng)烈建議使用mipmap裝圖片泉褐。把圖片放到mipmaps可以提高系統(tǒng)渲染圖片的速度届宠,提高圖片質(zhì)量烁落,減少GPU壓力。
然而問(wèn)題是我們?cè)赿rawable中引用mipmap資源的時(shí)候是沒(méi)有代碼提示的豌注,正確的做法就是直接自己動(dòng)手打吧
你看伤塌,這就沒(méi)有代碼提示
但是當(dāng)我們直接手動(dòng)輸入之后的樣子:
不會(huì)報(bào)錯(cuò)了