Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw NavigationView header below status bar with NavigationView behind status bar

I have been trying to draw the NavigationView header below the status bar, but it stays behind the status bar.

I have already set the property android:fitsSystemWindows="true" for both my DrawerLayout as well as my NavigationView, but to no avail.

Here's the 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

like image 969
Asad Tariq Avatar asked Jan 01 '17 22:01

Asad Tariq


1 Answers

I had the same issue, on your NavigationView set fitsSystemWindows to false, leave rest as is. From what I understood from API >= 21 NavigationView goes behind status bar

like image 165
Tuby Avatar answered Sep 24 '22 19:09

Tuby