PreferenceFragment中类别之间的分隔符

8

我想要实现设置应用程序的外观,这意味着我正在寻找在类别之间添加分隔符的解决方案。

Settings

所以我认为我找到了解决方案,但不幸的是它对我不起作用。正如建议的那样,我应该添加一个带有布局的空首选项:
</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>

但我得到的只是空白的偏好设置:

My

那我该怎么解决呢?


偏好类别之间的分隔线。 - user5762284
上面的图片来自设置应用程序,正是我想要的。 - user5762284
2
你实现了上述布局吗?你能否包含阴影背景以提供完整的解决方案。 - lostintranslation
1个回答

6

请尝试以下方法:

<?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>

4
我在我的类别之间使用了 @layout/divide_preference 添加了空白偏好设置类别,但是这给了我提示。谢谢! - user5762284
3
这对我没用,"@layout/divider_preference"无法解析。由于某种原因,它没有定义。我正在使用PreferenceFragment... - MahNas92

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接