修改checkbox框顏色
阿新 • • 發佈:2019-01-01
1、首先要匯入你準備用作CheckBox選中和沒有選中狀態的兩圖片到res的drawable中,如checkbox_checked.png,checkbox_normal.png。
2、在res/drawable中新增checkbox.xml,定義checkbox的state list drawable圖片。
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- checked -->
<item
android:state_checked="true"
android:drawable="@drawable/checkbox_checked"
/>
<!-- default -->
<item
android:state_checked="false"
android:drawable="@drawable/checkbox_normal"
/>
</selector>
3、在Layout中修改checkbox的屬性:android:button="@drawable/checkbox" 定製button樣式。
<CheckBox
android:layout_height="wrap_content"
android:id="@+id/chkItem"
android:button="@drawable/checkbox"
/>
這樣只需要修改checkbox.xml中的drawable的顏色即可實現自己所需的效果。