最终效果
minHeight,switchMinWidth调整switch开关高度、宽度
android:thumb 开关按钮上原型滑块的样式
android:track 开关按钮下面导轨的样式
<Switch
android:layout_width="48dp"
android:layout_height="24dp"
android:layout_marginEnd="21dp"
android:background="@null"
android:minHeight="24dp"
android:switchMinWidth="48dp"
android:thumb="@drawable/selector_switch_thumb"
android:track="@drawable/selector_switch_track"
app:layout_constraintBottom_toBottomOf="@+id/tv_br_top"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
selector_switch_thumb.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item android:width="18dp" android:height="24dp" android:drawable="@mipmap/ic_track" />
</layer-list>
</item>
</selector>
selector_switch_track.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false">
<layer-list>
<item android:width="48dp" android:height="24dp" android:drawable="@mipmap/ic_thumb_off" />
</layer-list>
</item>
<item android:state_checked="true">
<layer-list>
<item android:width="48dp" android:height="24dp" android:drawable="@mipmap/ic_thumb_on" />
</layer-list>
</item>
</selector>
对应素材
ic_thumb_off
ic_thumb_on
ic_track