1.在/res/drawble下创建button_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="@drawable/fwconfigon" />
<item android:state_checked="false"
android:drawable="@drawable/configoff" />
</selector>
2.在/res/values下创建styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyCheckBox" parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/checkbox_selector</item>
</style>
<style name="MyConifgswitch" parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/button_selector</item>
</style>
</resources>
3.然后可以在layout中正常使用MyConfigswitch
<CheckBox
android:id="@+id/config"
style="@style/MyConifgswitch"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_centerVertical="true"
android:layout_marginRight="31dp"
android:layout_toLeftOf="@+id/iv_logo"
android:visibility="invisible"
/>