自定义Checkbox样式--Android

1.在drawable文件夹下创建selector,如like_or_not_selector.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="@mipmap/icon_liked"/>
    <item android:state_checked="false" android:drawable="@mipmap/icon_like_not"/>

</selector>

2.在values文件夹中的style.xml文件中添加自定义style,如:

    <style name="CustomCheckBoxStyle" parent="@android:style/Widget.CompoundButton.CheckBox"> <item name="android:button">@drawable/like_or_not_selector</item> </style>

3.设置CheckBox样式

 <CheckBox
                android:layout_width="40dp" android:layout_height="40dp"
                style="@style/CustomCheckBoxStyle"
                android:checked="true"
                />

你可能感兴趣的:(android,checkbox,custom,自定义样式)