我无法在 CoordinatorLayout 中隐藏工具栏

I can not hide Toolbar in CoordinatorLayout

我附上了 xml 有一个 ScrollView,其中包含一些图像视图来测试工具栏是否可以隐藏。就我而言,它没有。

我用过buildToolsVersion "22.0.1"compile 'com.android.support:appcompat-v7:22.2.0'compile 'com.android.support:design:22.2.0'

解决方案是什么?

我的xml如下:

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

但是隐藏工具栏不起作用

ScrollView 不会与 Coordinator 布局相关联。使用 NestedScrollView 而不是 ScrollView。它会起作用。

here

它发生在我身上。我混淆了 ContraintLayout 和 CoordinatorLayout。这是 "have you switch off and switch on yet" 中我没有认真阅读的地方之一。我花了 3 个小时才明白为什么我的工具栏没有隐藏。不要让这种情况发生在你身上,特别是如果你使用由 Android Studios 生成的模板化 activity 布局。