It is necessary to implement the hide / display toolbar when scrolling content. (Just as, for example, in the play store application). How can this be realized?

<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" app:layout_scrollFlags="scroll|enterAlways"/> </android.support.design.widget.AppBarLayout> <su.gamepoint.opendomofon.pro.sliding.SlidingTabLayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" android:elevation="2dp" android:background="@color/ColorPrimary"/> <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_height="match_parent" android:layout_width="match_parent" android:layout_weight="1" app:layout_scrollFlags="scroll|enterAlways"/> </LinearLayout> </android.support.design.widget.CoordinatorLayout> 
  • 2
    You need CoordinatorLayout - YuriySPb
  • He is used - Big_Energy
  • Wrap now the toolbar in AppBarLayout, and add the necessary attributes for the ViewPager and the toolbar - Yuriy SPb
  • I updated the code in the header, anyway the toolbar is not hidden when scrolling. - Big_Energy
  • The ViewPager does not need a layout_scrollFlags, but a layoutBehavior. - Yuriy SPb

1 answer 1

At the root of your markup should be a CoordinatorLayout , and your ToolBar should be inside the AppBarLayout .

In ViewPager , behavior:

 <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"/> 

And it works with RecycleView , and it doesn't work with ListView .

I did for this article, there in English, but everything is simple: https://mzgreen.imtqy.com/2015/06/23/How-to-hideshow-Toolbar-when-list-is-scrolling(part3)/

Can help: https://stackoverflow.com/questions/33958878/hide-show-toolbar-programmatically-on-coordinatorlayout

  • It seems to work, but the toolbar will scroll only when you click on the toolbar itself, and if you scroll through the whole page, it’s in place - Big_Energy
  • @AndreyUzhegov so that he scrolls up needing it all to be in CoordinatorLayout, Toolbar in AppBarLayout, specified behavior and you scrolled RecycleView - Artem Shevchenko
  • @ AndreyUzhegov what do you have in ViewPager? - Artem Shevchenko
  • <android.support.v4.view.ViewPager android: id = "@ + id / pager" android: layout_height = "match_parent" android: layout_width = "match_parent" android: layout_weight = "1" app: layout_behavior = "@ string / appbar_scrolling_view_behavior "> </ android.support.v4.view.ViewPager> - Big_Energy
  • @ AndreyUzhegov, what are you posting in the ViewPager? - Artem Shevchenko