android - 文本在自定义布局中的涟漪效果之上以获得偏好
问题描述
我想为我的设置设置一个 SwitchPreference 的自定义布局。我可以成功地将布局更改为我想要的,但我有以下行为。当您点击某物时,此项目的文本位于 android 的涟漪效果之上。
下面我们可以看到首选项的简单版本
<PreferenceCategory
android:layout="settings_style_title"
app:iconSpaceReserved="false">
<SwitchPreference
android:defaultValue="true"
android:key="a_key"
android:title="this text gets above the effect"
android:layout="my_custom_layout" />
</PreferenceCategory>
和 my_custom_layout。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center_vertical">
<TextView
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="15dp"
android:fontFamily="sans-serif"
android:minHeight="25dp"
android:scrollbars="none"
android:singleLine="true"
android:textColor="#000000"
android:textSize="18sp"/>
<Switch
android:id="@android:id/switch_widget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"/>
</RelativeLayout>
我也尝试过使用android:widgetLayout
,但这仅控制小部件所在的空间,我无法为textview
.
然后我就试着直接给属性上了SwitchPreference
,只用了widgetLayout
还是不行。
我也尝试在里面设置标题my_custom_layout
。
我也尝试删除android:background
但没有效果。
我认为这与布局有关,因为当我检查它们时,偏好没有my_custom_layout
如下所示:
而带有它的那个看起来像这样:
还有什么是widget_frame?我似乎找不到任何包含它的地方,my_custom_layout
所以我可以拥有相同的结构。有什么想法吗?
解决方案
推荐阅读
- c# - 生产上的 SSIS 脚本任务使用 Microsoft.SharePoint.client 引发异常
- amazon-ecs - 如何从触发的 Fargate 任务中访问 CloudWatch 事件数据?
- java - Spring Boot 微服务 - 从数据库中检索数据
- python - 如何在python中找到两个字符串之间的最长交点?
- c++ - 为什么人们使用原子交换而不是存储?
- c# - .Net-Core Controller 操作不会在模型中绑定子复杂类型
- c++ - OpenAL 从特定时间戳播放音频
- javascript - 在打字稿中访问类属性
- android - 如何在颤动中禁用返回、主页和最近按钮?
- python - 将图像数据从 pandas 加载到 pytorch