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

前端 未结 8 2114
余生分开走
余生分开走 2021-01-30 11:30

When using the translucent status and navigation bars from the new Android 4.4 KitKat APIs, setting fitsSystemWindows=\"true\" and clipToPadding=\"false\"

8条回答
  •  一个人的身影
    2021-01-30 11:55

    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!

提交回复
热议问题