添加实体标题的首选项屏幕

发布于 2025-01-16 21:26:30 字数 553 浏览 2 评论 0原文

如何在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼睛会笑 2025-01-23 21:26:30

没有内置的实体标头首选项。您必须创建自己的首选项。

  1. 使用您自己的实体标头设计创建 xml 文件。这是 res/layout 文件夹中的文件。就我而言:
    entity_preference.xml

    <前><代码>

    <图像视图
    android:id="@+id/entity_image"
    机器人:layout_gravity =“center_horizo​​ntal”
    安卓:layout_width =“wrap_content”
    安卓:layout_height =“wrap_content”
    android:src="@mipmap/ic_launcher_foreground" //>

    <线性布局
    安卓:layout_width =“wrap_content”
    安卓:layout_height =“wrap_content”
    机器人:layout_marginHorizo​​ntal =“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="简要说明"
    >>

  2. 在“首选项”屏幕中使用该自定义设计。就我而言,这是 res/xml 中的 xml 文件:
    preference_screen.xml

    <前><代码> <编辑文本首选项
    应用程序:键=“标题文本”
    应用程序:标题=“标题”
    应用程序:useSimpleSummaryProvider =“true”/>

    [...]

结果首选项屏幕

There is no Entity header preference built in. You have to create your own.

  1. Create a xml file with your own Entity header design. This is a file in res/layout folder. In my case:
    entity_preference.xml:

     <LinearLayout
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:orientation="horizontal"
     android:background="@color/md_theme_light_secondaryContainer"
     android:gravity="center_horizontal|center_vertical"
     android:paddingVertical="16dp"
     xmlns:android="http://schemas.android.com/apk/res/android">
    
     <ImageView
         android:id="@+id/entity_image"
         android:layout_gravity="center_horizontal"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:src="@mipmap/ic_launcher_foreground" />
    
     <LinearLayout
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginHorizontal="6dp"
         android:orientation="vertical">
     <TextView
         android:id="@+id/entity_text"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="Title"
         android:textAppearance="@style/TextAppearance.Material3.HeadlineSmall"
         />
    
     <TextView
         android:id="@+id/entity_description"
         android:textAppearance="@style/TextAppearance.Material3.BodySmall"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="Brief description"
         />
     </LinearLayout>
    
  2. Use that custom design in your Preference screen. In my case this is a xml file in res/xml:
    preference_screen.xml:

     <EditTextPreference
         app:key="title_text"
         app:title="Title"
         app:useSimpleSummaryProvider="true" />
    

    [...]

Result preference screen

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文