Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide Toolbar on scroll with CoordinatorLayout

My app's action bar consists of a Toolbar and a tab view with a ViewPager to display the page's content. I am using a CoordinatorLayout so that I can hide the Toolbar on scroll, but it isn’t hiding. Here is my activity_main.xml:

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|enterAlways">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                android:fitsSystemWindows="true"
                app:contentInsetEnd="0dp"
                app:contentInsetStart="0dp"
                app:layout_scrollFlags="scroll|enterAlways">

                <include layout="@layout/actionbar" />
            </android.support.v7.widget.Toolbar>

            <com.whatsgoodly.views.SlidingTabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/purple"
                app:layout_scrollFlags="scroll|enterAlways" />
        </android.support.design.widget.AppBarLayout>

        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="0dp”
            android:layout_weight="1"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    </LinearLayout>
</android.support.design.widget.CoordinatorLayout>

Any thoughts?

like image 926
Chris Sebastian Avatar asked Sep 02 '26 12:09

Chris Sebastian


1 Answers

Add this to your android.support.v7.widget.Toolbar tag:

app:layout_collapseMode="parallax"
like image 148
Aakash Avatar answered Sep 05 '26 16:09

Aakash



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!