2

我一直在試圖在狀態欄下方繪製NavigationView標題,但它保留在狀態欄的後面。在狀態欄下方繪製NavigationView標題

我已經爲我的DrawerLayout以及我的NavigationView設置了屬性android:fitsSystemWindows="true",但無濟於事。

這裏的XML

<?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/activity_dashboard" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="start"> 

    <android.support.design.widget.CoordinatorLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <android.support.design.widget.AppBarLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="?attr/colorPrimary" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       app:layout_scrollFlags="scroll|enterAlways|snap"> 

      </android.support.v7.widget.Toolbar> 

      <android.support.design.widget.TabLayout 
       android:id="@+id/tab" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       app:tabMode="scrollable"> 

      </android.support.design.widget.TabLayout> 

     </android.support.design.widget.AppBarLayout> 

    </android.support.design.widget.CoordinatorLayout> 

    <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:background="@android:color/white" 
     android:fitsSystemWindows="true" 
     app:headerLayout="@layout/nav_header" /> 

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

This is how it looks currently

+0

你有沒有找到這個解決方案? –

+1

@RayKoopa將這條線android:fitsSystemWindows =「false」添加到抽屜佈局 – bebosh

回答

0

我有同樣的問題,您NavigationView設置fitsSystemWindows爲false,留下其餘不變。 從我理解的API> = 21導航視圖後面的狀態欄

+1

,這樣做會使NavigationView BELOW成爲狀態欄。我不想要這種行爲。我希望NavigationView在狀態欄後面繪製,但標題應該在狀態欄下方。 –

0

您是否嘗試將android:fitsSystemWindows="true"添加到您的標題佈局的根目錄?這對我有效。

+0

你可以在他的代碼中看到他自己的代碼,這會導致他的導航視圖位於狀態欄下方,但不會顯示它。 –