I am updating the Navigation Drawer in my app. I want to add section dividers as the Gmail App has. How do I add them? Just add them as views, which is a simple approach. But, i want to know, is it the correct approach?
Gmail App:
Right now, I am using a listview with a header view.
My current xml:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include
android:id="@+id/toolbar"
layout="@layout/toolbar_with_spinner" />
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</LinearLayout>
<ListView
android:id="@+id/listview_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/white"
android:choiceMode="singleChoice"
android:divider="@null"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
What is the correct approach of achieving something like the Gmail Navigation?
Use NavigationView inside DrawerLayout as its second child. Insert items in menu and apply menu attribute to NavigationView to display list items in Navigation Drawer. You can then give group id to menu items to be placed inside which will automatically creates a divider. For broader explanation, pls follow :
How to create a simple divider in the new NavigationView?
Use Menu Resources instead of listview. the group tag in menu creates a divider line
menu_drawer
Link the menu resources in navigation view
I used headerview and footerview to add the image on top and divider at the bottom. The divider is a View.
drawer_list_footer_divider.xml
drawer_list_footer_view.xml
and in my code: