简体   繁体   中英

hide Toolbar while scrolling

I have TabLayout below Toolbar and below the TabLayout I have SearchLayout (CustomView) I need to hide Toolbar while scrolling. I tried many ways but it's not happening Is there any solution for the same?

在此处输入图片说明

Here is my xml code

<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:background="@color/background">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <include
        android:id="@+id/toolbar_search_screen"
        layout="@layout/toolbar"
        app:layout_scrollFlags="scroll|enterAlways" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout"
        style="@style/AppTabLayout"
        android:layout_width="match_parent"
        android:layout_height="@dimen/_45sdp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/tool_bar"
        app:tabGravity="fill"
        app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>

<RelativeLayout
    android:id="@+id/search_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/_90sdp">

    <include layout="@layout/search_layout" />
</RelativeLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/viewPager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="@dimen/_45sdp"
    android:overScrollMode="never"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

Just add appropriate scroll flags to Toolbar :

app:layout_scrollFlags="scroll|enterAlways"

And appropriate behavior to the scrolling view (in your case to SwipeRefreshLayout and ViewPager ):

app:layout_behavior="@string/appbar_scrolling_view_behavior"

Inside viewPager views, it's children must be scrollable, otherwise it won't work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM