如何处理低于 28 的 android API 中的缺口(显示切口)? [英] How to handle notch(display cutout) in android API lower than 28?
问题描述
Android 在 API 28 上添加了缺口支持,但如何在运行 API 27(荣耀 10、华为 P20 等)的设备上处理它?
Android added notch support on API 28, but how to handle it on devices running API 27 (Honor 10, Huawei P20, etc.) ?
我试图使用 DisplayCutoutCompat
但我无法创建它的实例,因为文档并没有真正指出如何创建一个实例.
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.
如何创建构造函数参数值:Rect safeInsets
、List
?
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);
}
这将始终在运行 API 的设备上返回 null <28.提前致谢.
This will always return null on devices running API < 28. Thank you in advance.
推荐答案
Google 在 Android P 中提供了 Notch 相关的 API..
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.
我也没有在官方文档中看到创建 DisplayCutoutCompat 实例,但您可以按如下方式创建 DisplayCutout:
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();
}
这篇关于如何处理低于 28 的 android API 中的缺口(显示切口)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!