Toolbar not hiding in RecyclerView scroll

I am trying to make the Toolbar in my application hide and show based on the scrolling RecyclerView . This gif shows what I'm trying to achieve.

GIF

I am following this tutorial and not getting the results I am looking for. Here is my activity layout:

 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/coordinatorLayout" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:fitsSystemWindows="true"> <android.support.v4.widget.DrawerLayout android:id="@+id/drawer" android:layout_width="match_parent" android:layout_height="match_parent" android:elevation="7dp"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <include layout="@layout/toolbar" /> </android.support.design.widget.AppBarLayout> <FrameLayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FFFFFF" /> <android.support.design.widget.NavigationView android:id="@+id/navigation_view" android:layout_height="match_parent" android:layout_width="match_parent" android:layout_gravity="start" app:headerLayout="@layout/header" app:menu="@menu/drawer" /> </android.support.design.widget.CoordinatorLayout> 

And here is the layout of the Toolbar :

 <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:theme="@style/ThemeOverlay.AppCompat.Dark" android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="?attr/actionBarSize" android:background="@color/ColorPrimary" app:layout_scrollFlags="scroll|enterAlways" /> 

When I run this code, the Toolbar completely disappears. What's wrong?

+7
android android-recyclerview android-toolbar
source share
3 answers

If your RecyclerView is inside the fragment, try putting the following code in the root view of the fragment layout: app:layout_behavior="@string/appbar_scrolling_view_behavior" . The view that contains this must be a direct child of the CoordinatorLayout

+2
source share

As described in @ orrett3, just add this line

  app:layout_behavior="@string/appbar_scrolling_view_behavior" 

into your FrameLayout container like this

 <FrameLayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FFFFFF" app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

I assumed that RecyclerView is a child of this container.

0
source share

You need to do 2 actions:

  1. remove this line from the xml toolbar:

    Application: layout_scrollFlags = "Spiral | enterAlways"

  2. Like the other answers, add this line to the layout that will wrap your fragment (in your case, this is the frame layout)

    Application: layout_behavior = "@ string / appbar_scrolling_view_behavior"

0
source share

All Articles