I implemented a navigation drawer, with navigation view. and i am adding value in navigation view through a menu.xml file.
<android.support.design.widget.NavigationView
android:id="@+id/nvView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:itemTextColor="@android:color/white"
android:background="?attr/colorAccent"
app:menu="@menu/drawer_view"
app:headerLayout="@layout/nav_header"
>
</android.support.design.widget.NavigationView>
every thing is working fine, but i am facing a problem, I want to display submenu's , after click on menu.
I tried many thing's like:-
I add submenu in menu.xml, inside item. somthing like this..
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_ChangeOutlet_fragment"
android:icon="@drawable/home_icon"
android:title="@string/changeOutlet"
android:checked="true">
<menu>
<group>
<item
android:title="one"></item>
<item
android:title="two"></item>
<item
android:title="three"></item>
</group>
</menu>
then it return me output like this.
Output: click on this link to see output
https://drive.google.com/file/d/0B0B9-WZYydK7RG1yY0tRdkhOSW8/view?usp=sharing
Now problem is that, in this way i am not able to click on menu , only sub menu are clickable here.
I want here to show sub menu , only after click on menu, otherwise sub menu does shown to other or say it is in invisible state
I prefer you should go with custom layout in side navigation drawer.
Here is sample link - how to implement custom layout in navigation drawer.
You also need to implement expandable listview in side navigation drawer for your scenario, here is sample of expandable list view.
You need to combine both things to achive navigation drawer with expandable list.
The best solution is to have an expandable list view in navigation view.See the code below activity_navigation_view.xml
The layout navigation header is as below navigation_view_header.xml
In your navigation view activity, set the adapter for the expandable list view. NavigationViewActivity.java
The adapter for expandable list view is as follows
list_submenu.xml is as follows
listheader.xml is as follows
I have posted whole code for clarity. Hope this helps.......
You can create it using a ExpandableListview.
look at this here