Android NavigationView submenu title not showing

Hi i am using android NavigationView

. I have a group of items and subitems as Menu

items for a drawer.

Here the submenu items appear below the separator after the main menu items, but the problem is that the title for the submenu is not displayed. Subitems are displayed just below the divider with no title. I can't figure out what the problem is.

Inserting a menu tag inside a group of sub items and putting all sub items inside that menu tag will fix the problem, but it only makes the selected items (selected) after it has been selected 2 times. How can I fix this?

Here is my code:

<?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>
            <item
                android:id="@+id/nav_home"
                android:checkable="true"
                android:icon="@drawable/ic_person"
                android:title="Item1" />
            <item
                android:id="@+id/nav_messages"
                android:checkable="true"
                android:icon="@drawable/ic_attach"
                android:title="Item2" />
            <item
                android:id="@+id/nav_friends"
                android:checkable="true"
                android:icon="@drawable/icon"
                android:title="Item3" />
            <item
                android:id="@+id/nav_discussion"
                android:checkable="true"
                android:icon="@drawable/ic_exit"
                android:title="Item4" />

        </group>



<item android:title="Select Submenu">

    <group  android:id="@+id/group2"
            android:title="Select Submenu"
            >

            <item
                android:id="@+id/sub1"
                android:checkable = "true"
                android:icon="@drawable/sub_icon1"
                android:title="Sub Item1" />
            <item
                android:id="@+id/open"
                android:checkable = "true"
                android:icon="@drawable/sub_icon2"
                android:title="Sub Item2" />
            <item
                android:id="@+id/active"
                android:checkable = "true"
                android:icon="@drawable/sub_icon3"
                android:title="Sub Item3" />

        </group>
</item>

      

+3


source to share


1 answer


Use this. You are including the group in the element.

see this link for design library.

Replace the file with

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

<group android:checkableBehavior="single">
    <item
        android:id="@+id/nav_home"
        android:icon="@drawable/ic_dashboard"
        android:title="Home" />
    <item
        android:id="@+id/nav_messages"
        android:icon="@drawable/ic_event"
        android:title="Messages" />
    <item
        android:id="@+id/nav_friends"
        android:icon="@drawable/ic_headset"
        android:title="Friends" />
    <item
        android:id="@+id/nav_discussion"
        android:icon="@drawable/ic_forum"
        android:title="Discussion" />
</group>

<item android:title="Sub items"
      android:layout_gravity="bottom"
    >
    <menu>
        <item
            android:icon="@drawable/ic_dashboard"
            android:title="Sub item 1" />
        <item
            android:icon="@drawable/ic_forum"
            android:title="Sub item 2" />
    </menu>
</item>

      



This is my conclusion

enter image description here

+4


source







All Articles