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



如何添加这样的名为">实体标题";在文档中列出的首选项屏幕中:https://source.android.com/devices/tech/settings/settings-guidelines#entity_headerhttps://source.android.com/devices/tech/settings/settings-guidelines#user_education

我在Jetpack Preferences或其他资源中找不到任何元素,我如何在PreferenceScreen中添加这样的标题。

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

  1. 使用自己的Entity头设计创建一个xml文件。这是res/layout文件夹中的一个文件。就我而言: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. 在"首选项"屏幕中使用该自定义设计。在我的例子中,这是一个res/xml格式的xml文件:preference_screen.xml

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

    […]

结果偏好屏幕

最新更新