PreferenceFragment 中类别之间的分隔线

Divider between category in PreferenceFragment

我正在尝试实现“设置”应用的外观,这意味着我正在寻找在类别之间添加分隔线的解决方案。

所以我以为我找到了解决方案,但不幸的是它对我不起作用。正如所建议的那样,我应该在布局中添加空偏好:

</PreferenceCategory>
    <Preference
        android:title="Test"
        android:summary="Summary"/>

</PreferenceCategory>

<Preference layout="@layout/divider_preference" />

<PreferenceCategory
    android:title="Category"/>

这里是分频器:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="10dp"
              android:orientation="vertical">

    <View
        android:layout_width="match_parent"
        android:layout_height="5dp"
        android:background="@drawable/shadow_bottom"/>

    <View
        android:layout_width="match_parent"
        android:layout_height="5dp"
        android:background="@drawable/shadow_top"/>

</LinearLayout>

但我得到的只是空偏好:

那我该如何解决呢?

试试这个:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <PreferenceCategory
        android:layout="@layout/divider_preference"
        android:title="Category1">

    <Preference
        android:title="Test"
        android:summary="Summary"/>

    </PreferenceCategory>

    <PreferenceCategory
        android:layout="@layout/divider_preference"
        android:title="Category2">

    <Preference
        android:title="Test1"
        android:summary="Summary1"/>

    </PreferenceCategory>
</PreferenceScreen>