我目前正在开发一个应用程序,我想启用透明状态栏。我希望一个ImageView
(我需要它的scaleType
属性)覆盖整个屏幕,以便图像将显示在状态栏下方。这是我的布局:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="@drawable/picture" />
<android.support.v7.widget.Toolbar
(...toolbar stuff...)
/>
(...some other stuff...)
</RelativeLayout>
<include layout="@layout/drawer" />
</android.support.v4.widget.DrawerLayout>
正如您所看到的,这是一个常规的DrawerLayout
。请注意,DrawerLayout
、RelativeLayout
和ImageView
都将fitsSystemWindows
属性设置为true。
我的问题是:如果我在上面的代码中对DrawerLayout
或RelativeLayout
中的任何一个设置背景资源(比如颜色或图片),我可以看到该颜色或图片“出现”在状态栏下方,完全符合我的要求。但是,ImageView
的'src' drawable始终显示在其下方,就好像完全忽略了fitsSystemWindows
属性一样。
我的主题中有以下属性:
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@color/primary_dark</item>
由于primary_dark是半透明黑色(无论如何,这似乎不重要,因为正如我所说,这似乎是仅适用于我的ImageView
的问题。透明状态栏对于DrawerLayout
或RelativeLayout
都可以完美工作。