更新:这是一个 example app .我已经在我的 Nexus 6P、Android 6.0.1 上测试过了
我正在使用 CoordinatorLayout
和 RecyclerView
.
如果<item name="android:windowTranslucentNavigation">true</item>
工具栏没有隐藏(但它本身是可滚动的)。 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>
如果我添加 android:fitsSystemWindows="true"
至 AppBarLayout
它可以解决一些问题。
有什么解决办法吗?
最佳答案
看来这是一个错误。我找到了该问题的临时解决方案。
删除 Coordinator Layout 及其子项中的所有 android:fitsSystemWindows,或将它们设置为 false。然后在您的 Activity 中手动将状态栏的高度添加到工具栏的高度和顶部填充:
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;
}
通过这些更改,工具栏可以正确滚动,并且具有适当的高度。
关于android - 如果半透明导航为真,AppBarLayout 中的工具栏不会滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36224255/