material design - Android NavigationView sub-menu heading not showing -


hi using android navigationview. have group of items , sub items menu items drawer.

here sub-menu items appearing below divider after main menu items, problem heading sub menu not showing up. sub items showing just below divider without header. cant figure out problem.

inserting menu tag inside sub items group , putting sub items inside menu tag fix issue makes sub items getting selected(appearing selected) after selecting 2 times. how can fix this?

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

use . enclosing group item.

see this link design library.

replace file

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

enter image description here


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -