Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make DrawerLayout to display below the Toolbar?

How to make the drawer layout be below the actionbar/toolbar? I'm using v7:21 app compat library with the new ToolBar view.

Examples that I see looks like

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/my_drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent">  <!-- drawer view --> <LinearLayout     android:layout_width="304dp"     android:layout_height="match_parent"     android:layout_gravity="left|start">      <!-- drawer content -->  </LinearLayout>  <!-- normal content view --> <LinearLayout     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical">      <!-- The toolbar -->     <android.support.v7.widget.Toolbar           android:id="@+id/my_awesome_toolbar"         android:layout_height="wrap_content"         android:layout_width="match_parent"         android:minHeight="?attr/actionBarSize"         android:background="?attr/colorPrimary" />      <!-- The rest of content view -->  </LinearLayout>   

But then the toolbar will be hidden by the drawer, which makes an animated hamburger icon (like v7.ActionBarDrawerToggle) useless since it will not be visible below the drawer, but I do want to use the new ToolBar view to support Material theme better.

So how to accomplish that? Is it possible to have DrawerLayout as a non top-level view?

like image 395
user1309971 Avatar asked Oct 20 '14 11:10

user1309971


People also ask

How do you use DrawerLayout?

To use a DrawerLayout, position your primary content view as the first child with width and height of match_parent and no layout_gravity> . Add drawers as child views after the main content view and set the layout_gravity appropriately. Drawers commonly use match_parent for height with a fixed width.

How do I add a navigation drawer in Mainactivity?

To add a navigation drawer, first declare a DrawerLayout as the root view. Inside the DrawerLayout , add a layout for the main UI content and another view that contains the contents of the navigation drawer.


2 Answers

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent">      <!-- The toolbar -->     <android.support.v7.widget.Toolbar           android:id="@+id/my_awesome_toolbar"         android:layout_height="wrap_content"         android:layout_width="match_parent"         android:minHeight="?attr/actionBarSize"         android:background="?attr/colorPrimary" />      <android.support.v4.widget.DrawerLayout     xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/my_drawer_layout"     android:layout_width="match_parent"     android:layout_height="match_parent">          <!-- drawer view -->         <LinearLayout             android:layout_width="304dp"             android:layout_height="match_parent"             android:layout_gravity="left|start">              <!-- drawer content -->          </LinearLayout>          <!-- normal content view -->         <LinearLayout             android:layout_width="match_parent"             android:layout_height="match_parent"             android:orientation="vertical">                <!-- The rest of content view -->          </LinearLayout>       </android.support.v4.widget.DrawerLayout>  </LinearLayout>   
like image 124
Alexander Mamutov Avatar answered Sep 20 '22 06:09

Alexander Mamutov


i don't think you can when using custom toolbar

but a work around would be to set a top_margin to drawer. (the same thing on google play store!)

<!-- drawer view --> <LinearLayout     android:layout_marginTop="?attr/actionBarSize" ... 

if you found a better solution tell me too ;)

like image 31
EC84B4 Avatar answered Sep 23 '22 06:09

EC84B4