androidtoolbarandroid-design-library

I can not hide Toolbar in CoordinatorLayout


I have attached xml has a ScrollView which include some imageview to test that toolbar can hide or not. In my case it doesn't.

I have used buildToolsVersion "22.0.1" and compile 'com.android.support:appcompat-v7:22.2.0' and compile 'com.android.support:design:22.2.0'

What is the solution for that ?

My xml is as below :

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toorbar"
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:background="?attr/colorPrimary"
            android:minHeight="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"/>
    </android.support.design.widget.AppBarLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/drawer_header"/>
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/drawer_header"/>
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/drawer_header"/>
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/drawer_header"/>
        </LinearLayout>

    </ScrollView>
</android.support.design.widget.CoordinatorLayout>

but it not work to hide toolbar


Solution

  • ScrollView won't associate with CoordinatorLayout.

    Use NestedScrollView instead of ScrollView. It'll Work.

    NestedScrollView documentation