Search code examples
androidlandscapeandroid-cutout

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


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.


Solution

  • 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.