Reputation: 117
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>
Upvotes: 1
Views: 1191
Reputation: 1427
put the android:fitsSystemWindows="true"
to your emp_header
which you mention in app:headerLayout="@layout/emp_header"
Upvotes: 0
Reputation: 263
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...
Upvotes: 0
Reputation: 2295
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" />
Upvotes: 0
Reputation: 67296
Try removing android:fitsSystemWindows="true"
to your DrawerLayout
or making it false like android:fitsSystemWindows="false"
, probably this should work for you.
Upvotes: 1