我的代码
<style name="CustomSwitch">
<item name="android:switchMinWidth">0dp</item>
<item name="android:track">@drawable/switch_track</item>
<item name="android:thumb">@drawable/switch_thumb</item>
<item name="android:textOff">NO</item>
<item name="android:textOn">YES</item>
</style>
切换曲目
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true"
android:shape="rectangle"
android:useLevel="false"
android:visible="true">
<solid android:color="@color/colorTransparentGrey"></solid>
<corners android:radius="@dimen/switch_thumb_radius" />
<size android:height="@dimen/switch_track_height" />
</shape>
切换拇指
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false">
<shape android:shape="rectangle">
<size android:width="@dimen/switch_track_width" />
<corners android:radius="@dimen/switch_thumb_radius" />
<solid android:color="@color/colorAccent" />
<stroke android:color="@color/colorTransparent" android:width="@dimen/switch_thumb_padding"></stroke>
</shape>
</item>
<item android:state_checked="true">
<shape android:shape="rectangle">
<size android:width="@dimen/switch_track_width" />
<corners android:radius="@dimen/switch_thumb_radius" />
<solid android:color="@color/colorPrimary" />
<stroke android:color="@color/colorTransparent" android:width="@dimen/switch_thumb_padding"></stroke>
</shape>
</item>
</selector>