【问题标题】:How to make toolbar hide on scroll android studio如何在滚动android studio上隐藏工具栏
【发布时间】:2019-08-09 00:54:17
【问题描述】:

我试图让我的应用程序上的工具栏在应用程序上向下滚动时消失。我目前的设置似乎无法弄清楚。我想知道我是否可以通过现在如何设置我的工具栏来完成此任务,或者我是否需要重做我的工具栏?

我尝试添加,

app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"

因为有人让我把它放进去,但它似乎不起作用。

我的工具栏:

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

【问题讨论】:

    标签: java android xml android-studio


    【解决方案1】:

    工具栏需要是 AppBarLayout 的子级才能在滚动时隐藏。我相信 AppBarLayout 也必须包含在 CoordinatorLayout 中。

    不久前对这个问题的回答有一个很好的工作示例:CoordinatorLayout doesn't hide the actionbar

    【讨论】:

      猜你喜欢
      • 2019-04-21
      • 2014-12-19
      • 1970-01-01
      • 1970-01-01
      • 2016-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多