2016-11-14 122 views
1

我创建了一个导航抽屉。我想在状态栏下面显示抽屉。它可以正常工作。但抽屉在版本5上的状态栏上方打开, above.I要设置的抽屉像第二image.How设置下面状态栏的动作(即)的所有导航抽屉version.`设置在android中的操作栏上的抽屉导航

<?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

+0

这是你要补充的吗? http://stackoverflow.com/a/36587544/5188159 –

+0

没有不喜欢,我需要打开状态栏下面的抽屉。你的例子像抽屉打开下面的操作栏 –

+0

啊,它让我看到mm –

回答

0

尝试删除android:fitsSystemWindows="true"到您的DrawerLayout或使它像android:fitsSystemWindows="false"一样虚假,可能这应该适合您。

+0

我已经尝试过,但不能正常工作 –

+0

,适合我! –

0

这种替换代码:

<?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" /> 

0

我所做的是找到状态栏的高度和偏移它。

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); 

用于获取状态栏高度的功能是:

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

希望有所帮助。

Ps。这一发现状态栏的高度我知道了别人很久以前的某个地方......

+0

你的答案工作良好,但有一点是如果我为headerlayout设置填充意味着一些文本移动inside.so,我已经为mNavView设置填充。 –

+0

之后,它工作正常,但我的预期,但灰色显示在状态栏的顶部。是否有任何可能性设置在mNavView动态边距,而不是填充 –

+0

我认为如果你移动边距,它会暴露您看到的灰色背景。所以我认为填充比边缘更好。 顺便说一句,你是什么意思的一些文本被移动到里面? – Aung

0

android:fitsSystemWindows="true"emp_header您在app:headerLayout="@layout/emp_header"