CheckBox自定義樣式
阿新 • • 發佈:2018-11-11
設定ChekBox的複選框不顯示
setButtonDrawable((new ColorDrawable(Color.TRANSPARENT)))
1)在drawable中新建一個checkbox.xml
例:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/color_appname" android:state_checked="true"/> <item android:drawable="@color/color_maplng" android:state_checked="false"/> <item android:drawable="@color/color_maplng"/> </selector>
例(字型):
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:color="@color/color_white" android:state_checked="true"/> <item android:color="@color/color_black" android:state_checked="false"/> <item android:color="@color/color_black"/> </selector>
2)在Styles中新建
<style name="CustomCheckboxTheme" parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:background">@drawable/checkbox_style</item>
<item name="android:textColor">@drawable/checkbox_textcolor_style</item>
</style>
3)在checkBox設定屬性時引用
style="@style/CustomCheckboxTheme"