SwitchCompact 使用说明
一、布局中使用
1.1 文字
- app:showText =====> 设置是否显示开/关文本
- android:textOff =====> 设置开关没有选中时显示的文本
- android:textOn =====> 设置开关选中时显示的文本
- app:switchTextAppearance =====> 设置开关文本颜色、大小、样式、提示颜色和高亮颜色
1.2 轨道
- app:track =====> 设置轨道样式
- app:trackTint =====> 设置轨道颜色
- app:trackTintMode =====> 设置轨道颜色的混合模式
- app:splitTrack =====> 是否设置一个间隙,让滑块与底部图片分隔(API 21及以上)
- app:switchMinWidth =====> 设置轨道宽度
1.3 滑块设置
- android:thumb =====> 设置滑块样式
- app:thumbTextPadding =====> 设置滑块上文本的水平填充距离
- app:thumbTint =====> 设置滑块颜色
- app:thumbTintMode =====> 设置滑块颜色的混合模式
1.4 案例
1.4.1 在 styles.xml 中创建文字样式
<style name="AppSwitch" parent="Theme.AppCompat.Light">
<item name="android:textSize">16sp</item>
<item name="android:textColor">#22AA22</item>
<item name="android:textStyle">italic</item>
</style>
1.4.2 建轨道样式
// shape_track_off.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="1000dp" />
<solid android:color="#E1E1E1" />
</shape>
// shape_track_on.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corn