[英]Android: Hide/Show Toolbar while scrolling doesn't work
我有一個非常簡單的布局:
<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>
我添加了一個Fragment
與標准RecyclerView
到fragment_container
。 不幸的是, Toolbar
總是隱藏的,我不明白為什么?
非常感謝您的幫助!
您可以嘗試以下方法: 類似問題的解決方案。
基本上,您必須使用android.support.v4.widget.NestedScrollView
而不是ScrollView
(在您的片段中),並在NestedScrollView xml中實現app:layout_behavior="@string/appbar_scrolling_view_behavior"
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.