Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle notch(display cutout) in android API lower than 28?

Android added notch support on API 28, but how to handle it on devices running API 27 (Honor 10, Huawei P20, etc.) ?

I was trying to use DisplayCutoutCompat but I was not able to create an instance of it since documentation does not really point out how create one.

How to create the constructor parameter values: Rect safeInsets, List<Rect> boundingRects?

I also looked into the source code of the constructor, which is a bit confusing to me:

public DisplayCutoutCompat(Rect safeInsets, List<Rect> boundingRects) {
        this(SDK_INT >= 28 ? new DisplayCutout(safeInsets, boundingRects) : null);
    }

This will always return null on devices running API < 28. Thank you in advance.

like image 294
blade Avatar asked Aug 08 '18 09:08

blade


People also ask

How do I turn off display cutout?

Go to Settings > Display & brightness > More display settings > Cutout, and select Default. If you want to show or hide the notch for a specific app, touch Custom, select the app, then select one of the following options: Auto. Show cutout.

What is display cutout developer options?

Display cutouts allow you to create immersive, edge-to-edge experiences while still allowing space for important sensors on the front of devices. Android 9 supports the following types of cutouts: Top center: Cutout at the center of the top edge. Top uncentered: Cutout may be in the corner or slightly off-center.

What is tall cutout on Android?

A display cutout is an area on some devices that extends into the display surface. It allows for an edge-to-edge experience while providing space for important sensors on the front of the device. Android supports display cutouts on devices running Android 9 (API level 28) and higher.

How do I hide notch on Android 11?

Go into developer options and scroll 3/4 of the way down to the Drawing section. In there you have a setting called Display cutout. Change that to hide.


1 Answers

Google provided notch related APIs in Android P. Devices with notch and API version lower than P implemented their own notch APIs.You can consult the APIs from device specified documentation.

Also I did not see creation of DisplayCutoutCompat instance in official documentation, but you can create DisplayCutout as follow:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            DisplayCutout displayCutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
}
like image 165
fujino ryougi Avatar answered Sep 20 '22 03:09

fujino ryougi