Android 如果半透明导航为true,则AppBarLayout中的工具栏不会滚动关闭

Android 如果半透明导航为true,则AppBarLayout中的工具栏不会滚动关闭,android,scroll,navigation-drawer,android-toolbar,android-coordinatorlayout,Android,Scroll,Navigation Drawer,Android Toolbar,Android Coordinatorlayout,更新:以下是一个示例。我已经在我的Nexus6p,Android 6.0.1上测试过了 我正在使用CoordinatorLayout和RecyclerView。 如果true工具栏未隐藏(但它本身可滚动)。appcompat是v7:23.2.1 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="h

更新:以下是一个示例。我已经在我的Nexus6p,Android 6.0.1上测试过了

我正在使用
CoordinatorLayout
RecyclerView
。 如果
true
工具栏未隐藏(但它本身可滚动)。appcompat是v7:23.2.1

<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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

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

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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

有顶部和底部的衬垫

协调布局
(可能)使用工具栏滚动
这似乎是一个bug。我找到了这个问题的临时解决办法

清除协调器布局中的所有android:fitsSystemWindows及其子项,或者将它们设置为false。然后在活动中手动将状态栏的高度添加到工具栏的高度和顶部填充:

toolbar.setPadding(0, getStatusBarHeight(), 0, 0);
toolbar.getLayoutParams().height = toolbar.getLayoutParams().height + getStatusBarHeight();
获取状态栏高度的方法:

public int getStatusBarHeight() {
    int height = 0;
    int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        height = getResources().getDimensionPixelSize(resourceId);
    }
    return height;
}

通过这些更改,工具栏可以正常滚动,并且具有适当的高度。

您能找到解决问题的方法吗?