更改系統(tǒng)Switch樣式:只要是thumb(圓形前景開關(guān))和track(長圓背景)屬性镶苞。
示例代碼
1.使用
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:thumb="@drawable/shape_thumb"
android:track="@drawable/shape_track"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_content" />
2.track
<!--drawable/shape_track-->
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size
android:width="20dp"
android:height="10dp" />
<corners android:radius="10dp" />
<stroke
android:width="6dp"
android:color="#00000000" />
<solid android:color="#CFCFCF" />
</shape>
3.thumb
<!--drawable/shape_thumb-->
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size android:width="15dp" />
<size android:height="15dp" />
<stroke
android:width="1dp"
android:color="#CFCFCF" />
<solid android:color="@color/color_selector_thumb" />
</shape>
<!--color/color_selector_thumb-->
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#333333" android:state_checked="true" />
<item android:color="#EDEDED" android:state_checked="false" />
</selector>