添加实体标题的首选项屏幕
如何在 PreferenceScreen 中添加名为“Entity Header”的内容,如此处文档中列出的: https://source.android.com/devices/tech/settings/设置指南#entity_header https://source.android.com/devices/tech/settings/ settings-guidelines#user_education
我在 Jetpack Preferences 或其他资源中找不到任何元素,如何在 PreferenceScreen 中添加此类标头。
How can I add such called "Entity Header" in a PreferenceScreen like listed in the docs here:
https://source.android.com/devices/tech/settings/settings-guidelines#entity_header
https://source.android.com/devices/tech/settings/settings-guidelines#user_education
I can't find any element in Jetpack Preferences or other resource how I can add such header inside the PreferenceScreen.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有内置的实体标头首选项。您必须创建自己的首选项。
使用您自己的实体标头设计创建 xml 文件。这是 res/layout 文件夹中的文件。就我而言:
entity_preference.xml:
<前><代码>
<图像视图
android:id="@+id/entity_image"
机器人:layout_gravity =“center_horizontal”
安卓:layout_width =“wrap_content”
安卓:layout_height =“wrap_content”
android:src="@mipmap/ic_launcher_foreground" //>
<线性布局
安卓:layout_width =“wrap_content”
安卓:layout_height =“wrap_content”
机器人:layout_marginHorizontal =“6dp”
android:orientation="垂直">
<文本视图
android:id="@+id/entity_text"
安卓:layout_width =“wrap_content”
安卓:layout_height =“wrap_content”
机器人:文本=“标题”
android:textAppearance="@style/TextAppearance.Material3.HeadlineSmall"
>>
<文本视图
android:id="@+id/entity_description"
android:textAppearance="@style/TextAppearance.Material3.BodySmall"
安卓:layout_width =“wrap_content”
安卓:layout_height =“wrap_content”
android:text="简要说明"
>>
在“首选项”屏幕中使用该自定义设计。就我而言,这是 res/xml 中的 xml 文件:
preference_screen.xml:
<前><代码> <编辑文本首选项
应用程序:键=“标题文本”
应用程序:标题=“标题”
应用程序:useSimpleSummaryProvider =“true”/>
[...]
结果首选项屏幕
There is no Entity header preference built in. You have to create your own.
Create a xml file with your own Entity header design. This is a file in res/layout folder. In my case:
entity_preference.xml:
Use that custom design in your Preference screen. In my case this is a xml file in res/xml:
preference_screen.xml:
[...]
Result preference screen