API 21 中的 CollapsingToolbarLayout

CollapsingToolbarLayout in API 21

如果您查看 cheesesquare 应用程序中的 CheeseDetailActivity,CollapsingToolbarLayout 似乎导致 Toolbar 在 API 上未对齐 21:

这也会导致 Toolbar 在向下滚动后被遮挡:

据推测,它应该是这样的(API 18 截图):

有没有人遇到过这个问题或知道使工具栏正确对齐的解决方案?

由于 v21 主题更改为包括:

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

需要在工具栏上修改 v21 的边距以考虑系统栏占用的 space。

dimens.xml

<dimen name="action_bar_margin_top">0dp</dimen>

dimens.xml (v21)

<dimen name="action_bar_margin_top">-24dp</dimen>

将 margin 和 fitsSystemWindows 添加到 Toolbar

<android.support.v7.widget.Toolbar
    android:layout_marginTop="@dimen/action_bar_margin_top"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:fitsSystemWindows="true"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:layout_collapseMode="pin" />