Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation Drawer Below Toolbar

I am trying to get the navigation drawer to open below the toolbar.

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/drawer_layout" tools:context=".MainActivity"> <RelativeLayout     android:layout_width = "match_parent"     android:layout_height = "wrap_content">     <include layout="@layout/toolbar"         android:id="@+id/toolbar"/>     <FrameLayout         android:layout_below="@+id/toolbar"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:background="@color/background_color"/> </RelativeLayout> <ListView     android:id="@+id/drawer"     android:layout_width="260dp"     android:layout_height="match_parent"     android:layout_below="@+id/toolbar"     android:layout_marginTop="56dp"     android:layout_gravity="start"> </ListView> </android.support.v4.widget.DrawerLayout> 

How do I reformat the xml so that the navigation bar opens below the toolbar?

like image 940
safaiyeh Avatar asked Nov 18 '14 01:11

safaiyeh


People also ask

How do I get navigation drawer in all activity?

The user can view the navigation drawer when they swipe the activity's screen from the left edge of the android device. A user can also find it from the activity, by tapping the app icon (also known as the “hamburger” menu) in the action bar.

How do I customize my navigation drawer?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. Step 3 − Add the following code to res/layout/nav_header_main.


1 Answers

You should move DrawerLayout as top parent and move Toolbar out of DrawerLayout content container. In short this looks like:

RelativeLayout  ----Toolbar  ----DrawerLayout      ---ContentView      ---DrawerList  

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/top_parent"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:fitsSystemWindows="true"     tools:context=".MainActivity">      <include         android:id="@+id/toolbar"         layout="@layout/toolbar" />      <android.support.v4.widget.DrawerLayout         android:id="@+id/drawer_layout"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:layout_below="@+id/toolbar">          <FrameLayout             android:id="@+id/content_frame"             android:layout_width="match_parent"             android:layout_height="match_parent"             android:background="@color/background_color" />          <ListView             android:id="@+id/drawer"             android:layout_width="260dp"             android:layout_height="match_parent"             android:layout_below="@+id/toolbar"             android:layout_gravity="start"             android:layout_marginTop="56dp" />      </android.support.v4.widget.DrawerLayout> </RelativeLayout> 

However, Material Design guidelines state that Navigation Drawer should be above the Toolbar.

like image 169
Nikola Despotoski Avatar answered Sep 23 '22 11:09

Nikola Despotoski