1. 程式人生 > >改變checkbox控制元件框的顏色

改變checkbox控制元件框的顏色


1.在drawable中放入選中狀態和未選中狀態的兩張圖片
2.新建checkbox.xml檔案,新增    
<item
android:state_checked="true"
android:drawable="@drawable/checkbox_checked"
/>
<item
android:state_checked="false"
android:drawable="@drawable/checkbox_normal"
/>
3.在layout中的checkbox控制元件中新增
android:button="@drawable/checkbox"
4.(或不3)在styl.xml中新增新的styles,item指定checkbox,然後再layout中呼叫即可。
<style name="CustomCheckBox" parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/checkbox</item>
</style>
style="@style/CustomCheckBox"
5. 缺點是狀態轉換生硬,看著很不爽,優點是想要什麼樣式換圖片就ok。