简体   繁体   English

如何使工具栏隐藏在滚动Android Studio上

[英]How to make toolbar hide on scroll android studio

I'm trying to make the toolbar on my app disappear when scrolling down on the app. 我试图在向下滚动应用程序时使应用程序上的工具栏消失。 I can't seem to figure it out with my current setup. 我目前的设置似乎无法弄清楚。 I was wondering if there was something I could to accomplish this with how my toolbar is set up right now or do I need to redo my toolbar? 我想知道是否可以通过现在设置工具栏来完成此任务,还是需要重做工具栏?

I tried to add, 我尝试添加

app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"

because I someone told me to put it in, but it doesn't seem to work. 因为有人告诉我放进去,但这似乎行不通。

My toolbar: 我的工具栏:

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

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/global_color_primary"
            android:elevation="4dp"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        <FrameLayout
            android:id="@+id/fragment_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />


    </LinearLayout>

The Toolbar needs to be the child of an AppBarLayout for it to be able to hide on scroll. 工具栏必须是AppBarLayout的子级,才能在滚动时隐藏。 I believe the AppBarLayout must also be contained within a CoordinatorLayout as well. 我相信AppBarLayout也必须包含在CoordinatorLayout中。

The answer to this question from a while back has a nice working example: CoordinatorLayout doesn't hide the actionbar 不久前这个问题的答案有一个很好的工作示例: CoordinatorLayout不会隐藏操作栏

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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