Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
201 views
in Technique[技术] by (71.8m points)

android - NavigationView: how to insert divider without subgroup?

How I can put a divider without title Subgroup in the new NavigationView?

<?xml version="1.0" encoding="utf-8"?>

<menu xmlns:android="http://schemas.android.com/apk/res/android">


<group android:checkableBehavior="single">
    <item
        android:id="@+id/drawer_armario"
        android:icon="@drawable/armario"
        android:title="@string/armario"  />
    <item
        android:id="@+id/drawer_amigos"
        android:icon="@drawable/amigos"
        android:title="@string/amigos" />

</group>

<item android:title="Configuración">
    <menu>
        <item

            android:id="@+id/drawer_ajustes"
            android:icon="@drawable/ajustes"
            android:title="@string/ajustes" />
        <item
            android:id="@+id/drawer_ayuda"
            android:icon="@drawable/ayuda"
            android:title="@string/ayuda" />
        <item
            android:id="@+id/drawer_sign_out"
            android:icon="@drawable/sign_out"
            android:title="@string/sign_out" />

    </menu>

</item>

I would like to put a line beetween amigos and ajustes items without Configuración title.

Thanks!!!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

All you need to do is define a group with an unique ID. I looked through NavigationView's implementation, and it will create a divider every time the group id is changed.

e.g.

<group android:id="@+id/my_id">
    <!-- Divider will appear above this item -->
    <item ... />
</group>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...