1

I have created a navigation drawer.I want to show the drawer below the status bar .Its works fine as what i'm expected.But the drawer open above the status bar on version 5 and above.I want set the drawer as like the second image.How to set the navigation drawer on the action(i.e) below status bar for all version.`

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="close"
   >

    <include
        layout="@layout/emp_app_bar_home"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_gravity="start"

        android:fitsSystemWindows="true"

        app:itemTextColor="@color/black"
        app:itemIconTint="@color/black"
        android:background="@drawable/menubg"
        app:headerLayout="@layout/emp_header"
        app:menu="@menu/activity_emp_drawer" />


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

` drawer opens above action bar in versaion 5+ mobiles

image2

enter image description here

Abserve Tech
  • 117
  • 2
  • 11

4 Answers4

1

Try removing android:fitsSystemWindows="true" to your DrawerLayout or making it false like android:fitsSystemWindows="false", probably this should work for you.

Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
0

Replace your code with this:

<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<include
    layout="@layout/emp_app_bar_home"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:itemTextColor="@color/black"
    app:itemIconTint="@color/black"
    android:background="@drawable/menubg"
    app:headerLayout="@layout/emp_header"
    app:menu="@menu/activity_emp_drawer" />

Abhi
  • 2,115
  • 2
  • 18
  • 29
0

What I did was to find the height of the statusbar and offset it.

private NavigationView mNavView;
private View mHeaderView;
//...
mNavView = (NavigationView) findViewById(R.id.navView);
//...
mHeaderView = mNavView.getHeaderView(0);
//...
LinearLayout mHeaderLayout = (LinearLayout) HeaderView.findViewById(R.id.headerLayout);
//..
mHeaderLayout.setPadding(0, getStatusBarHeight(), 0, 0);

The function for getting statusbar height is:

public int getStatusBarHeight() {
        int result = 0;
        int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = getResources().getDimensionPixelSize(resourceId);
        }
        return result;
}

Hope that helps.

Ps. The find statusbar height I got it somewhere else long time ago...

Aung
  • 253
  • 1
  • 5
  • 15
  • Your answer working good but one thing is if i set padding for headerlayout means some of the text is move inside.so that i have set padding for mNavView. – Abserve Tech Nov 14 '16 at 13:10
  • After that it works fine as what i'm expected but the gray color is shown in top of the status bar.Is there any possibilty for setting the margins dynamically in mNavView instead of padding – Abserve Tech Nov 14 '16 at 13:10
  • I think if you shift the margin, it will expose the background which is the grey color you saw. So I think padding is better than margin. By the way, what do you mean by some of the text is moved inside ? – Aung Nov 14 '16 at 13:15
  • If you look closely, I shifted the layout not the header itself nor the navigation view. I think you can try to wrap everything inside one layout and then top padding that layout. – Aung Nov 14 '16 at 13:18
  • see that posted image it contain username and email id.That emailid get move i inside the layout – Abserve Tech Nov 14 '16 at 13:20
  • Can you include your header .xml ? – Aung Nov 14 '16 at 13:24
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/128064/discussion-between-abserve-tech-and-aung). – Abserve Tech Nov 14 '16 at 13:26
0

put the android:fitsSystemWindows="true" to your emp_header which you mention in app:headerLayout="@layout/emp_header"

Furqan
  • 1,417
  • 1
  • 15
  • 22