[英]Android: Hide/Show Toolbar while scrolling doesn't work
I have this very simple layout:
我有一个非常简单的布局:
<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>
I add a Fragment
with a standard RecyclerView
into fragment_container
. 我添加了一个
Fragment
与标准RecyclerView
到fragment_container
。 Unfortunately, the Toolbar
is always hide, I can't understand why? 不幸的是,
Toolbar
总是隐藏的,我不明白为什么?
Thank you very much for your help guys! 非常感谢您的帮助!
You could try this: solution from similar question. 您可以尝试以下方法: 类似问题的解决方案。
Basically, you have to use android.support.v4.widget.NestedScrollView
instead of ScrollView
(in your fragment) and implement app:layout_behavior="@string/appbar_scrolling_view_behavior"
inside your NestedScrollView xml. 基本上,您必须使用
android.support.v4.widget.NestedScrollView
而不是ScrollView
(在您的片段中),并在NestedScrollView xml中实现app:layout_behavior="@string/appbar_scrolling_view_behavior"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.