【问题标题】:Android: Hide/Show Toolbar while scrolling doesn't workAndroid:滚动时隐藏/显示工具栏不起作用
【发布时间】:2017-04-08 09:40:17
【问题描述】:

我有这个非常简单的布局:

<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/tools"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ActionBarThemeOverlay">

        <!--<include layout="@layout/include_toolbar_actionbar" />-->

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways" />

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

    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/background"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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

我将带有标准RecyclerViewFragment 添加到fragment_container 中。不幸的是,Toolbar 总是隐藏,我不明白为什么?

非常感谢你们的帮助!

【问题讨论】:

    标签: android android-studio android-appbarlayout android-collapsingtoolbarlayout


    【解决方案1】:

    你可以试试这个:solution from similar question.

    基本上,您必须使用android.support.v4.widget.NestedScrollView 而不是ScrollView(在您的片段中)并在您的NestedScrollView xml 中实现app:layout_behavior="@string/appbar_scrolling_view_behavior"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-28
      • 1970-01-01
      相关资源
      最近更新 更多