Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Sections and Subheader in android material drawer Recyclerview items?

I have used the following tutorial to implement material design drawer.

http://www.androidhive.info/2015/04/android-getting-started-with-material-design/

But i want to add sections in the drawer after 2 items. How to make the recyclerview display sections and subheaders?

like image 390
Mihir Shah Avatar asked Feb 10 '23 04:02

Mihir Shah


1 Answers

You better use the design support library to do this. specifically android.support.design.widget.NavigationView class Checkout the following links for more

  • Tutorial
  • Github sample

Some code snippets from sample:

activity_main.xml

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/drawer_layout"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:fitsSystemWindows="true">


    <include layout="@layout/include_list_viewpager"/>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/drawer_view"/>

</android.support.v4.widget.DrawerLayout>

And menu shown on drawer will have a separator at the end of the first menu group.
drawer_view.xml

<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_discussion"
            android:icon="@drawable/ic_forum"
            android:title="Discussion" />
    </group>

    <item android:title="Sub items">
        <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>

</menu>
like image 68
makata Avatar answered Apr 30 '23 14:04

makata