I am experiencing an issue when using Coordinator Layout that contains an AppBarLayout (holding a ToolBar and a TabLayout) and a ViewPager (holding fragments) as children. I want the topbar to be hidden when scrolling down, and revealed when scrolling back up. However when I scroll down, the status bar scrolls up as well, leaving the top bar just below the status icons, being overlapped by them.
I tried adding android:fitsSystemWindows="true" to both the AppBarLayout and the ViewPager but nothing changed.
Below the code used and snapshots showing the two states:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
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"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMaxWidth="0dp"
app:tabGravity="fill"
app:tabMode="fixed"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
fitsSystemWindows="true"
on yourAppBarLayout
, b) Add acontentScrim
to yourAppBarLayout
orToolbar
(app:contentScrim="@color/primaryDark"
), or c) try aCollapsingToolbarLayout
instead ofAppBarLayout
, but don't give it collapsing scroll flags. Hope one of those helps!