You can add layout_marginTop like this,
<android.support.design.widget.NavigationView android:layout_marginTop="@dimen/abc_action_bar_default_height_material" android:id="@+id/nav_view" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" android:fitsSystemWindows="true" app:headerLayout="@layout/nav_header_main" app:menu="@menu/activity_main_drawer" />
but the box will appear as the top layer on the toolbar.
Here is another Choppy way to add it below to the toolbar !!!
may not be the best, but it works!
The end result will look like this:

If you create a project as a Navigation Drawer Activity project, it will provide you with four XML files when created in your layout folder
- app_bar_main
- content_main
- navigatin_main
activity_main

How are these xmls connected? basically i see include tag
Your activity is related to Activity_main
activity_main has app_bar_main and navigation_view (box)app_bar_main has toolbar and content_main by default
Now it allows you to remove activity_main and set its contents directly to the main application panel and use it as the main layout for Activity.
To add a box under the toolbar, add it under android.support.design.widget.AppBarLayout , because it contains a toolbar, and it should be on top.
here is an example app_bar_main.XML
<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:context="none.navhead.MainActivity"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.AppBarLayout> //------ taken from activity_main // content main <include layout="@layout/content_main" /> // you need this padding <android.support.v4.widget.DrawerLayout android:paddingTop="?attr/actionBarSize" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" tools:openDrawer="start"> <android.support.design.widget.NavigationView android:id="@+id/nav_view" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" android:fitsSystemWindows="true" app:headerLayout="@layout/nav_header_main" app:menu="@menu/activity_main_drawer" /> </android.support.v4.widget.DrawerLayout> </android.support.design.widget.CoordinatorLayout>
ps you can set app_bar_main.XML in setContentView of your activity just play, there are many ways;)
Charu āļ Apr 13 '16 at 2:35 2016-04-13 02:35
source share