Activity not extended below the cutout in landscape

494 views Asked by At

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.stack.imgur.com/7va88.png

  compileSdkVersion 29
  buildToolsVersion '29.0.3'

  minSdkVersion 21
  targetSdkVersion 29

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

1

There are 1 answers

0
Java42 On BEST ANSWER

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.