【发布时间】:2016-06-09 07:42:13
【问题描述】:
我正在尝试将图像设置为可折叠工具栏,该工具栏显示在 >23api 的半透明状态栏后面。但是即使在styles.xml中将状态栏设置为透明并从清单中为活动应用主题并在imageview和collapsingToolbar的布局中设置fitSystemWindows之后,图像也不会应用于状态栏。 xml 和它的外观截图:
布局.xml
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:fitsSystemWindows="false"
android:layout_height="match_parent" >
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="250dp" >
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
android:id="@+id/movie_banner"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffe5e5e5"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="10dp">
<android.support.v7.widget.RecyclerView
android:id="@+id/movies_details_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
app:layout_anchor="@id/app_bar_layout"
app:layout_anchorGravity="bottom|right|end"
style="@style/FabStyle"/>
</android.support.design.widget.CoordinatorLayout>
styles.xml
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:textColorPrimary">@android:color/white</item>
</style>
这是我手机上的样子。
--------------------更新-------- Jakson 的回答部分解决了这个问题。现在,当工具栏向上滚动时,图像被设置为状态栏,但是,一旦它完全向上,我会看到如下图。请注意,操作栏也向上移动了一点。 我需要实现这样的目标:image set over statusbar
【问题讨论】:
-
显示你最新的 xml
-
感谢您的回答。现在可以了。显然错过了 appbarlayout 中的 fitSystemWindows。现在效果很好。
标签: android xml android-coordinatorlayout android-collapsingtoolbarlayout