在视图滚动时隐藏工具栏

3
我在使用FragmentRecyclerView。我想在滚动RecyclerView时隐藏Fragment的工具栏,但是仅通过设计无法完全隐藏Toolbar。如何解决这个问题? 开始滚动点: enter image description here 最终滚动点: enter image description here 这里是MainActivity.xml
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.avalank.financy.Main2ActivityTest">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/appbar_padding_top"
        android:theme="@style/AppTheme.AppBarOverlay">

        <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"
            app:popupTheme="@style/AppTheme.PopupOverlay">

        </android.support.v7.widget.Toolbar>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

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

    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>
2个回答

0

0

你说得对,我已经尝试过了,在Styles.xml中不需要下面的代码就可以正常工作:

<item name="android:windowTranslucentStatus">true</item>

最后,检查这个答案的两种方法/技巧:https://dev59.com/EVsW5IYBdhLWcg3wSFjW#35241363 此外,您可以使用 CollapsingToolbarLayout 并添加一些标志,例如:
app:layout_scrollFlags="scroll|snap"

另外,让我们提一下我已经删除了这行代码:
android:paddingTop="@dimen/appbar_padding_top"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接