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.
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.
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.
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.
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.
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With