Gurleen Sethi
Gurleen Sethi

Reputation: 31

How to prevent AppBarLayout going behind the status bar?

The AppBarLayout is going behind the status bar. I have made navigation bar translucent. If I use fitSystemWindow then the content doesn't show below the navigation bar. I want to retain content below navigation bar and make the AppBarLayout below status bar

<?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"
    android:id="@+id/fragment_main_drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <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.support.v7.widget.Toolbar
                android:id="@+id/fragment_main_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:title="@string/app_name"
                app:layout_scrollFlags="scroll|enterAlways"
                app:titleTextColor="@android:color/white"/>

            <android.support.design.widget.TabLayout
                android:id="@+id/fragment_main_tab_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:minHeight="?attr/actionBarSize"
                app:tabBackground="@android:color/white"
                app:tabGravity="fill"
                app:tabIndicatorColor="@color/colorPrimary"
                app:tabMaxWidth="0dp"
                app:tabSelectedTextColor="@color/colorPrimary"
                app:tabTextColor="@color/tab_unselected">

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

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

        <android.support.v4.view.ViewPager
            android:id="@+id/fragment_main_view_pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

        </android.support.v4.view.ViewPager>

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

    <android.support.design.widget.NavigationView
        android:layout_width="280dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/colorPrimary">
        <ImageView
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:layout_gravity="bottom|right"
            android:src="@drawable/navbar_bottom"/>

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

Upvotes: 1

Views: 1195

Answers (2)

Paulina
Paulina

Reputation: 970

You should set android:fitsSystemWindows="true" to your top-level layout (in this case DrawerLayout)

Upvotes: 2

Gary Bak
Gary Bak

Reputation: 4798

Try adding this to your CoordinatorLayout

android:fitsSystemWindows="true"

Formats: boolean

Boolean internal attribute to adjust view layout based on system windows such as the status bar. If true, adjusts the padding of this view to leave space for the system windows. Will only take effect if this view is in a non-embedded activity.

Upvotes: 0

Related Questions