Android 11 - window.setDecorFitsSystemWindow doesn't show screen behind Status and Navigation Bars

16.4k views Asked by At

I'm trying to update my App to Android 11. Many Screens of my App were Designed with App Content behind the StatusBar. I Updated my gradle to Android 11 and started updating the Window code to get the No Limit behavior also for Android 11 Devices. I achived my desired result for pre Android 11 Devices with the folowing Code in my Activitiys onCreate method:

Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

I tried to get the same no limit behavior for Android 11 by using w.setDecorFitsSystemWindows(false);

I tried using it instead of using the flags, using it with flags and passing true and false, setting it before and after setting the flags but i always see a white status and system navigation bar instead of my Apps content behind them. What i tried:

Window window = getWindow();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
    window.setDecorFitsSystemWindows(false); //also tried with true
} else {
    window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}

//or
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
    window.setDecorFitsSystemWindows(false); //also tried with true
} 
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

//or
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
    window.setDecorFitsSystemWindows(false); //also tried with true
} 

My App still is in Java Code, i tried window?.setDecorFitsSystemWindows(false) in another app which uses Kotlin code and it worked without any troubles.

Does anyone have an idea what i'm missing or doing wrong here?

2

There are 2 answers

0
Vinay Revankar On

For android 11 along with flags we also need to add below styles in the app theme

<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
1
Alexey Timokhin On

My App still is in Java Code, i tried window?.setDecorFitsSystemWindows(false) in another app which uses Kotlin code and it worked without any troubles.

Kotlin internally uses Java, so it does not matter whether you code in Java or Kotlin in terms of that insets API.

Probably, one of the view groups, which you use in your view hierarchy, consumes insets and does not propagate them to the child views. This was my case - my app is using DebugDrawer and window.setDecorFitsSystemWindows(false); didn't have any effect on the layout in my case. There is even the solution for that case. Maybe you could use it too, if you have a similar problem. It could be helpful to check the view hierarchy in the new Layout Inspector of Android Studio. Pay attention to the views that have attribute fitsSystemWindows = true. Also, that answer could be helpful.