Android 4.4 — Translucent status/navigation bars — fitsSystemWindows/clipToPadding don't work through fragment transactions Android 4.4 — Translucent status/navigation bars — fitsSystemWindows/clipToPadding don't work through fragment transactions android android

Android 4.4 — Translucent status/navigation bars — fitsSystemWindows/clipToPadding don't work through fragment transactions


I struggled with the same problem yesterday. After thinking a lot, I found an elegant solution to this problem.

First, I saw the method requestFitSystemWindows() on ViewParent and I tried to call it in the fragment's onActivityCreated() (after the Fragment is attached to the view hierarchy) but sadly it had no effect. I would like to see a concrete example of how to use that method.

Then I found a neat workaround: I created a custom FitsSystemWindowsFrameLayout that I use as a fragment container in my layouts, as a drop-in replacement for a classic FrameLayout. What it does is memorizing the window insets when fitSystemWindows() is called by the system, then it propagates the call again to its child layout (the fragment layout) as soon as the fragment is added/attached.

Here's the full code:

public class FitsSystemWindowsFrameLayout extends FrameLayout {    private Rect windowInsets = new Rect();    private Rect tempInsets = new Rect();    public FitsSystemWindowsFrameLayout(Context context) {        super(context);    }    public FitsSystemWindowsFrameLayout(Context context, AttributeSet attrs) {        super(context, attrs);    }    public FitsSystemWindowsFrameLayout(Context context, AttributeSet attrs, int defStyle) {        super(context, attrs, defStyle);    }    @Override    protected boolean fitSystemWindows(Rect insets) {        windowInsets.set(insets);        super.fitSystemWindows(insets);        return false;    }    @Override    public void addView(View child, int index, ViewGroup.LayoutParams params) {        super.addView(child, index, params);        tempInsets.set(windowInsets);        super.fitSystemWindows(tempInsets);    }}

I think this is much simpler and more robust than hacks that try to determine the UI elements sizes by accessing hidden system properties which may vary over time and then manually apply padding to the elements.


I solved the issue by using the library I use the set the color of my translucent status bar.

The SystemBarConfig class of SystemBarTint (as seen here https://github.com/jgilfelt/SystemBarTint#systembarconfig) lets you get insets which I set as the padding to the list in every fragment, along with the use of clipToPadding="false" on the list.

I have details of what I've done on this post: http://mindofaandroiddev.wordpress.com/2013/12/28/making-the-status-bar-and-navigation-bar-transparent-with-a-listview-on-android-4-4-kitkat/


Okay, so this is incredibly weird. I just recently ran into this same issue except mine involves soft keyboard. It initially works but if I add fragment transaction, the android:fitsSystemWindows="true" no longer works. I tried all the solution here, none of them worked for me.

Here is my problem:enter image description here

Instead of re-sizing my view, it pushes up my view and that is the problem.

However, I was lucky and accidentally stumbled into an answer that worked for me!

So here it is:

First of all, my app theme is: Theme.AppCompat.Light.NoActionBar (if that is relevant, maybe it is, android is weird).

Maurycy pointed something very interesting here, so I wanted to test what he said was true or not. What he said was true in my case as well...UNLESS you add this attribute to your activity in the android manifest of your app:

enter image description here

Once you add:

android:windowSoftInputMode="adjustResize" 

to your activity, android:fitsSystemWindows="true" is no longer ignored after the fragment transaction!

However, I prefer you calling android:fitsSystemWindows="true" NOT on the root layout of your Fragment. One of the biggest places where this problem will occur is where if you have EditText or a ListView. If you are stuck in this predicament like I did, set android:fitsSystemWindows="true" in the child of the root layout like this:

enter image description here

YES, this solution works on all Lollipop and pre-lollipop devices.

And here is the proof:enter image description here

It re-sizes instead of pushing the layout upwards.So hopefully, I have helped someone who is on the same boat as me.

Thank you all very much!