android - 自定义 Android SwitchCompat
问题描述
在我的 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>
这就是我要的
解决方案
推荐阅读
- python - 根据值 Pandas 重命名列名
- ruby-on-rails - 如何在rails中按天数或日期名称获取日期?
- angular - 如何在量角器中执行拖放功能
- java - Java for Android 中的自定义对象检测
- reactjs - Firebase 部署命令正在部署一个非常旧的提交
- google-tag-manager - 自定义历史更改触发器以跳过 GTM 中同一页面上的 hashchanges
- scala - Calculating mean and standard deviation using Spark / SCALA
- ssas - PY YTD 计算的可以处理闰年 MDX 的度量
- c# - 如何让 VS Code 使用本地安装的 .NET Core?
- json - 使用 XSLT 提取 json 字段