Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Lollipop: ImageView ignoring fitsSystemWindows attribute (transparent status bar)

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.

like image 825
Sergio Morales Avatar asked Jan 27 '15 18:01

Sergio Morales


2 Answers

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.

like image 87
Bogdan Stadnyk Avatar answered Nov 19 '22 21:11

Bogdan Stadnyk


fitSystemWindows

does not work in RelativeLayout. Use a FrameLayout or a ViewGroup extending FrameLayout

like image 44
Julian Os Avatar answered Nov 19 '22 20:11

Julian Os