I'm currently working on an app for which I want to enable a transparent status bar. I want an ImageView (which I require for its scaleType attribute) to cover the entirety of the screen so that the image will show below the status bar. Here's my layout:
<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>
As you can see, it's a regular DrawerLayout. Notice that the DrawerLayout, the RelativeLayout and the ImageView all have the fitsSystemWindows attribute set to true.
My problem is: If I set a background resource (like a color or a picture) to either the DrawerLayout or the RelativeLayout in the above code, I can see that color or picture "below" the status bar, exactly as I want it, but the ImageView's 'src' drawable is always shown under it, as if it ignored the fitsSystemWindows attribute completely.
I have the following attributes in my theme:
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@color/primary_dark</item>
With primary_dark being a semitransparent black (this shouldn't matter anyway, since as I said, this seems to be an issue exclusive to my ImageView. The transparent status bar works perfect for either the DrawerLayout or the RelativeLayout.
This works perfectly for me
You have android:fitsSystemWindows="true"in every viewGroup params.
Try to left only one in ImageView.
Or completely remove all of them.
fitSystemWindows
does not work in RelativeLayout. Use a FrameLayout or a ViewGroup extending FrameLayout
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With