1创建Switch的开关头的样式文件 -- shape_switch_thumb.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#fff"/>
<size android:width="25dp"
android:height="25dp"/>
<corners android:radius="180dp"/>
</shape>
2创建Switch关闭状态的开关体的样式文件 -- shape_switch_track_close.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#8E8E8E"/>
<corners android:radius="20dp"/>
</shape>
3创建Switch开启状态的开关体的样式文件 -- shape_switch_track_open.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFAC63"/>
<corners android:radius="20dp"/>
</shape>
4创建开启关闭状态的资源使用文件 -- shape_switch_track_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/shape_switch_track_open" android:state_checked="true"/>
<item android:drawable="@drawable/shape_switch_track_close"
android:state_checked="false"/>
<item android:drawable="@drawable/shape_switch_track_close"
/>
</selector>
5xml中使用Switch控件
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:thumb="@drawable/shape_switch_thumb"
android:track="@drawable/shape_switch_track_selector"/>