Activity not extended below the cutout in landscape
Asked Answered
I

1

3

In my activity I use the following code to turn on / off fullscreen. And by fullscreen I mean hiding / showing the status bar. The problem takes place on devices that has a Cutout (Where there's a camera) and the Status bar is visible and in Landscape. It extends when status bar is hidden or / and in portrait.

    if(aStatus){ // Hide
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN , WindowManager.LayoutParams.FLAG_FULLSCREEN);

    } else {

        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

As in this picture, on the left the white area should be covered.

https://i.sstatic.net/7va88.png

  compileSdkVersion 29
  buildToolsVersion '29.0.3'

  minSdkVersion 21
  targetSdkVersion 29

There'll be a 50 Points reward for selected solution. Thank you!

Invar answered 14/10, 2020 at 4:59 Comment(6)
This is a complicated topic about Android versions, Windows, WindowInsets and fitsSystemWindow. I advice you to make yourself familiar with these terms and what they really do. There is a good talk about this by Chris Banes: youtube.com/watch?v=_mGDMVRO3iE I remember another talk also by him one or two years later. Shouldn't be hard to find on YouTube.Lazy
@Lazy You are scaring folks who are reading your comment. There is a simple solution to this problem. Set a background on the activities parent window.Cyclone
haha yeah maybe it sounds too harsh, sorry. Still worth watching. Thx for not being scared and providing a quick solution!Lazy
@Lazy I already watched this video a couple of yrs ago, I remember he was sarcastic about the status bar & the layout and how it was a bad design, am I right?Invar
let's call it "honest" instead of "sarcastic" ;) legacy is a bitch, yes...it will never go away. But I like his talks and medium articles, since they DO give you an understanding on how things work together. Even if it takes some time to wrap the head around everything involved.Lazy
@Lazy I totally agree! "Honest" is way much better of a choice than "Sarcastic". I'll recheck it again, maybe I'll come up with things that I missed 2yrs ago.Invar
C
6

Here is the fix. Tweak as necessary.

  1. Create a BitmapDrawable of your target color or image.
  2. Set that drawable on the activity's window.

Example:

Bitmap bitmap = Bitmap.createBitmap(24, 24, Bitmap.Config.ARGB_8888);
bitmap.eraseColor(Color.MAGENTA);
BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
getWindow().setBackgroundDrawable(bitmapDrawable);

Another Example:

Bitmap bitmap = Bitmap.createBitmap(24, 24, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(Color.MAGENTA);
BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
getWindow().setBackgroundDrawable(bitmapDrawable);

Both tested in Activity.onCreate.

Cyclone answered 16/10, 2020 at 23:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.