Android中如何修改CheckBox的顏色
多於話咱就不說了 直接上代碼
佈局中的代碼
<CheckBox
android:id="@+id/cbMember"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:button="@drawable/checkbox_ic_style"
android:text="會員"
android:textColor="@color/colorAccent"
android:textSize="24dp" />
checkbox_ic_style.xml
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_checked="true"
android:drawable="@drawable/ic_checkbox_selecte"
/>
<item
android:state_checked="false"
android:drawable="@drawable/ic_checkbox_unselecte"
/>
</selector>
ic_checkbox_selecte.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="30dp"
android:height="30dp"
android:viewportWidth="3000"
android:viewportHeight="3000">
<path
android:pathData="M372,2959c-121,-23 -235,-112 -293,-226l-34,-67 0,-1165 0,-1166 34,-67c59,-118 171,-203 301,-228 72,-14 2168,-14 2240,0 165,31 296,156 335,321 22,95 22,2182 0,2277 -20,85 -48,135 -109,200 -59,63 -137,106 -221,121 -71,13 -2186,13 -2253,0zM1293,2126c18,-8 263,-246 575,-558l542,-544 0,-46c0,-82 -67,-134 -142,-109 -23,8 -184,162 -528,506l-495,495 -240,-240 -241,-240 -46,0c-39,0 -52,5 -77,31 -35,35 -42,90 -17,137 24,46 558,570 586,575 44,8 50,7 83,-7z"
android:fillColor="#451507"
android:strokeColor="#451507"/>
</vector>
ic_checkbox_unselecte.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="30dp"
android:height="30dp"
android:viewportWidth="3000"
android:viewportHeight="3000">
<path
android:pathData="M372,2959c-121,-23 -235,-112 -293,-226l-34,-67 0,-1165 0,-1166 34,-67c59,-118 171,-203 301,-228 72,-14 2168,-14 2240,0 165,31 296,156 335,321 22,95 22,2182 0,2277 -20,85 -48,135 -109,200 -59,63 -137,106 -221,121 -71,13 -2186,13 -2253,0zM2650,2734c43,-25 61,-42 83,-84l27,-52 0,-1094c0,-967 -2,-1099 -16,-1132 -19,-47 -58,-88 -107,-113 -36,-19 -69,-19 -1133,-19 -1198,0 -1133,-3 -1198,58 -16,15 -37,45 -47,67 -18,38 -19,91 -19,1136l0,1095 26,52c28,57 86,99 153,113 20,4 518,6 1106,5l1070,-1 55,-31z"
android:fillColor="#451507"
android:strokeColor="#451507"/>
</vector>