How can I color the cutout/notch area in non-full screen landscape mode

1.5k views Asked by At

Here are two images taken in landscape mode. One is full screen mode and the other is normal mode. The issue I am trying to solve is how to color the left white area you see in the normal view. I'd like the color to be the same as the rest of the app. There is no concern with full screen view vs normal view in portrait mode which is working fine. The concern is only with landscape mode.

Has anyone had success in coloring the left hand side on a notched device in landscape mode?

An example of the the white area on the top and bottom of the left-hand notch. An example of the the white area on the top and bottom of the left-hand notch.

No concern with full-screen mode. Working fine. No concern with full-screen mode. Working fine.

2

There are 2 answers

2
Java42 On BEST ANSWER

Here is a fix for @AshrafAlshahawy:

  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.

0
Duna On

In your theme just add the color you want:

<item name="android:statusBarColor" tools:targetApi="l">@color/black</item>