在我的 Android 应用程序中,我有一个SwitchCompat用于过滤列表数据的列表。默认主题不能满足我的目的,我需要的是一个类似 iOS 的开关。我不知道如何自定义它以使其看起来与 iOS 开关完全一样。谢谢阅读。
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switch_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@xml/custom_switch_background_main"
android:theme="@style/AppTheme.SwitchOverlay"/>
这是我目前存档的
custom_switch_background_main.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false" android:drawable="@xml/custom_switch_background" />
<item android:state_checked="true" android:drawable="@xml/custom_switch_background" />
</selector>
custom_switch_background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="50dp" />
<solid android:color="@color/transparent" />
<stroke
android:width="1dp"
android:color="@color/hello" />
</shape>
这就是我要的





