Search code examples
androidxmlandroid-layoutandroid-5.0-lollipopmaterial-design

Navigation Drawer below Tool bar in Material Design


I want my drawer to open from the left below the tool bar. But, according to Material Design aspects that's not good. But still I want to do that.

Here I have changed my XML file.
---Relative Layout
-----Tool bar
-----Drawer
-------container
-------drawer List

here is my XML file. My app crashes when it opens. I don't know where I made a mistake and XML doesn't show any errors.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<include
    android:id="@+id/toolbar"
    layout="@layout/toolbar" />

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

    <FrameLayout
        android:id="@+id/container_body"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <fragment
        android:id="@+id/fragment_navigation_drawer"
        android:name="com.myApp.activity.FragmentDrawer"
        android:layout_width="@dimen/nav_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:layout="@layout/fragment_navigation_drawer"
        tools:layout="@layout/fragment_navigation_drawer" />

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

</RelativeLayout>

Solution

  • Here is the latest solution for material design

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:openDrawer="start">
    
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
    
    android:layout_height="@dimen/abc_action_bar_default_height_material"
            android:background="?attr/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
    
    </android.support.design.widget.AppBarLayout>
    
    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
       <!--content_main is my layout you can design your own-->
        <include layout="@layout/content_main" />
    
        <FrameLayout
            android:id="@+id/content"
            layout="@layout/content_main"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    
        <!-- The navigation drawer -->
        <android.support.design.widget.NavigationView
            android:id="@+id/nav_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            app:menu="@menu/activity_main_drawer" />
    
    </android.support.v4.widget.DrawerLayout>
    
    
    </LinearLayout>
    

    Hope it helps