1.xml中设置Switch控件
<Switch
android:id="@+id/individuationSwitch"
android:layout_width="40dp"
android:layout_height="20dp"
android:checked="false"
android:thumb="@drawable/thumb"
android:track="@drawable/track"
/>
2.底部滑动条颜色设置(track)
2.1: track 选择器
<?xml version="1.0" encoding="utf-8"?><!-- 底层下滑条的样式选择器,可控制Switch在不同状态下,底下下滑条的颜色 -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/blue_track" android:state_checked="true" />
<item android:drawable="@drawable/gray_track" />
</selector>
2.2: blue_track 打开状态
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 高度40 -->
<size android:height="15dp"/>
<!-- 圆角弧度20 -->
<corners android:radius="15dp"/>
<!-- 变化率 -->
android:endColor="@color/color_6495ED"
android:startColor="@color/color_6495ED" />
</shape>
2.3: gray_track 关闭状态
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<!-- 高度30 此处设置宽度无效-->
<size android:height="15dp"/>
<!-- 圆角弧度15 -->
<corners android:radius="15dp"/>
<!-- 变化率 定义从左到右的颜色不变 -->
android:endColor="@color/color_888888"
android:startColor="@color/color_888888" />
</shape>
3.滑动按钮颜色设置(thumb)
3.1:thumb 选择器
<?xml version="1.0" encoding="utf-8"?><!-- 按钮的选择器,可以设置按钮在不同状态下的时候,按钮不同的颜色 -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/blue_thumb" android:state_checked="true" />
<item android:drawable="@drawable/gray_thumb" />
</selector>
3.2:blue_thumb 打开状态
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<!-- 高度40 -->
<size android:height="20dp" android:width="20dp"/>
<!-- 圆角弧度20 -->
<corners android:radius="20dp"/>
<!-- 变化率 -->
android:endColor="@color/white"
android:startColor="@color/white" />
<stroke android:width="1dp"
android:color="@color/color_6495ED"/>
</shape>
3.3: gray_thumb 关闭状态
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<!-- 高度40 -->
<size android:height="20dp" android:width="20dp"/>
<!-- 圆角弧度20 -->
<corners android:radius="20dp"/>
<!-- 变化率 -->
android:endColor="@color/white"
android:startColor="@color/white" />
<stroke android:width="1dp"
android:color="@color/color_666666"/>
</shape>