How to get dividers in NavigationView menu without titles?

柔情痞子 提交于 2019-11-30 05:37:24
Kenny Worden

From: NavigationView: how to insert divider without subgroup?

It looks like you just need to give your group tags unique ID's.

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

As the answer says:

[NavigationView] will create a divider every time the group id is changed

This is exact solution for your question here.

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <group
        android:id="@+id/menu_top"
        android:checkableBehavior="single">
        <item android:title="Switch Team">
            <menu>
                <item
                    android:id="@+id/team"
                    android:title=""
                    app:actionLayout="@layout/layout_spinner_for_drawer"/>
            </menu>
        </item>
    </group>

    <group
        android:id="@+id/menu_bottom"
        android:checkableBehavior="single">
            <item
                android:id="@+id/nav_home"
                android:icon="@drawable/home"
                android:title="Home" />
            <item
                android:id="@+id/nav_share"
                android:icon="@drawable/sharebox"
                android:title="Sharebox" />
            <item
                android:id="@+id/nav_recognize"
                android:icon="@drawable/recognize"
                android:title="Recognize" />
            <item
                android:id="@+id/nav_contact_us"
                android:icon="@drawable/contactus"
                android:title="Contact Us" />
            <item
                android:id="@+id/nav_logout"
                android:icon="@drawable/signout"
                android:title="Logout" />
    </group>
</menu>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!