Toolbar经常会随着theme 以及style变化,今天发现一个问题就是,在项目中生成一个ScrollingActivity,
却出现Toolbar被系统栏覆盖了。
但是新建一个项目,默认生成ScrollingActivity,Toolbar却正常。
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
各种theme,style设置后,仍不起作用。比对后发现唯一不同的是support:appcompat-v7版本,果不其然,22.2.1以下版本跑在android 6.0以上是有问题的。改为22.2.1及以上版本就正常了。