我正在尝试学习CoordinatorLayout及其功能。我已经将它与AppBarLayout一起使用。我的XML代码如下:
<android.support.design.widget.CoordinatorLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.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:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_gravity="bottom|end"
style="@style/FabStyle"/>
</android.support.design.widget.CoordinatorLayout>
我面临的问题是,滚动工具栏会在状态栏下方。我希望当我滚动Recycler View时,工具栏也会随着滚动,但不要让它进入状态栏下方。如何防止这种情况发生。
此外,当我尝试将CoordinatorLayout封装在另一个布局中(例如LinearLayout)时,主题中定义的primaryDark颜色不会显示在状态栏中。当我像上面的xml一样使用它时,它会显示primaryDark颜色。有更好的方法吗?
android:fitsSystemWindows="true"
添加到了 CoordinatorLayout 中。 现在的问题已经通过从 CoordinatorLayout 中删除android:fitsSystemWindows="true"
并将其添加到 AppbarLayout 中来解决。 - superus8r