android - 为什么滚动时工具栏不隐藏?

标签 android android-toolbar

我正在使用工具栏和多个带有一些文本的 Textview,但是当我滚动时我试图隐藏我的工具栏但它没有隐藏,以下是我的 xml 代码任何人都可以帮助我,在此先感谢..

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

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



            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="pin" />



    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        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:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:orientation="vertical"

            android:paddingTop="24dp">



            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Product Name:"
                android:layout_marginLeft="5dp"
                android:textAppearance="@style/TextAppearance.AppCompat.Title" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/desc_prodname"
                android:layout_marginTop="5dp"
                android:layout_marginLeft="5dp"

                android:text="@string/cheese_ipsum"
                />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Brand:"
                android:layout_marginTop="10dp"
                android:layout_marginLeft="5dp"

                android:textAppearance="@style/TextAppearance.AppCompat.Title" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/desc_brandnm"
                android:layout_marginTop="5dp"
                android:layout_marginLeft="5dp"
                android:text="@string/cheese_ipsum"

                />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Description:"
                android:layout_marginLeft="5dp"

                android:textAppearance="@style/TextAppearance.AppCompat.Title" />
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/desc_description"
                android:layout_marginLeft="5dp"
                android:text="@string/cheese_ipsum"

                android:layout_marginTop="5dp"
                />
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Price:"
                android:layout_marginTop="10dp"
                android:layout_marginLeft="5dp"

                android:textAppearance="@style/TextAppearance.AppCompat.Title" />
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/desc_price"
                android:layout_marginTop="5dp"
                android:layout_marginLeft="5dp"
                android:text="@string/cheese_ipsum"

                />
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Category:"
                android:layout_marginTop="10dp"
                android:layout_marginLeft="5dp"

                android:textAppearance="@style/TextAppearance.AppCompat.Title" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/desc_catname"
                android:layout_marginTop="5dp"
                android:layout_marginLeft="5dp"

                />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Subcategory:"
                android:layout_marginTop="10dp"
                android:layout_marginLeft="5dp"

                android:textAppearance="@style/TextAppearance.AppCompat.Title" />
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/desc_subcatname"
                android:layout_marginTop="5dp"
                android:layout_marginLeft="5dp"

                />






        </LinearLayout>




    </android.support.v4.widget.NestedScrollView>

    <!--<android.support.design.widget.FloatingActionButton
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        app:layout_anchor="@id/appbar"
        app:layout_anchorGravity="bottom|right|end"
        android:src="@drawable/ic_discuss"
        android:layout_margin="@dimen/fab_margin"
        android:clickable="true"/>-->

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

最佳答案

把你的工具栏放在“NestedScrollView”里面

关于android - 为什么滚动时工具栏不隐藏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34922694/

相关文章:

android [java.lang.NoClassDefFoundError : android. widget.Toolbar]

android - 使用 fragment 内的recyclerview在滚动时隐藏工具栏

android.support.v7 Toolbar & DrawerLayout- 如何隐藏汉堡图标

android - 以编程方式更改 AppBarLayout 主题

java - 在 android 的蓝牙扬声器问题上听不到 twilio 语音通话

android - 如何获取私钥以在android中获取签名的apk文件?

android - 尝试在 Eclipse 上更新到 Android SDK 2.3 导致 adb 丢失

android - 我开发了一个在 api17 上工作的应用程序,但它无法在 api 8 上工作,但我已将最小 sdk 设置为 8

android - 下方带有水平进度条的工具栏

java - 如何使用数据库纠正 Recyclerview 中的此错误