Divider between category in PreferenceFragment

∥☆過路亽.° 提交于 2019-12-05 22:33:29

问题


I'm trying to achieve Settings app look, which means I'm looking for solution to add divider between categories.

So I thought I found solution, but unfortunately it's not working for me. As was suggested I should add empty preference with layout:

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

</PreferenceCategory>

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

<PreferenceCategory
    android:title="Category"/>

Here is divider:

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

But what I get is just empty preference:

So how could I fix that?


回答1:


Try with this:

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


来源:https://stackoverflow.com/questions/35601241/divider-between-category-in-preferencefragment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!