I am trying to change my Navigation Drawer to resemble that of the new Gmail App. I am using AppCompatv7 - v21, and have the updated sdk. What is it that i am missing? Please refer to the images below.
Gmail Navigation:
The navigation drawer, moves over the toolbar.
My current Navigation:
The navigation drawer, comes below the toolbar.
[EDIT]
This was my earlier XML code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include
android:id="@+id/toolbar"
layout="@layout/toolbar_with_spinner" />
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<ListView
android:id="@+id/listview_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/dark_grey"
android:choiceMode="singleChoice"
android:divider="@drawable/drawer_list_divider"
android:dividerHeight="2dp" />
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
Now as per the suggestion from pedro, I tried to move the toolbar inside drawerlayout.
Here is my new 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" >
<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>
<ListView
android:id="@+id/listview_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/white"
android:choiceMode="singleChoice"
android:divider="@drawable/drawer_list_divider"
android:dividerHeight="2dp" />
</android.support.v4.widget.DrawerLayout>
This is my current code in onCreate()
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
toolbar = (Toolbar) findViewById(R.id.toolbar);
spinner = (Spinner) toolbar.findViewById(R.id.spinner);
mDrawerList = (ListView) findViewById(R.id.listview_drawer);
Now, i don't even see the toolbar. Here is the image.
[EDIT]
Here is my new layout. This works.. thanks again pedro...
<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="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/white"
android:choiceMode="singleChoice"
android:divider="@drawable/drawer_list_divider"
android:dividerHeight="2dp" />
</android.support.v4.widget.DrawerLayout>
You have to put your toolbar inside your Drawer Layout.
Here is an example of a XML taken from this Github Project:
<?xml version="1.0" encoding="utf-8"?>
<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"
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_actionbar"
layout="@layout/toolbar_default"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<!-- android:layout_marginTop="?android:attr/actionBarSize"-->
<fragment
android:id="@+id/fragment_drawer"
android:name="com.poliveira.apps.materialtests.NavigationDrawerFragment"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="@layout/fragment_navigation_drawer"/>
</android.support.v4.widget.DrawerLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With