android - 如何处理低于 28 的 android API 中的缺口(显示切口)?

标签 android android-appcompat android-9.0-pie androidx

Android 在 API 28 上添加了刘海屏支持,但如何在运行 API 27 的设备(荣耀 10、华为 P20 等)上处理它?

我正在尝试使用 DisplayCutoutCompat但我无法创建它的实例,因为文档并没有真正指出如何创建它。

如何创建构造函数参数值:Rect safeInsets , List<Rect> boundingRects

我还查看了构造函数的源代码,这让我有点困惑:

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

这将始终在运行 API < 28 的设备上返回 null。 提前谢谢你。

最佳答案

Google 在 Android P 中提供了 notch 相关的 API。notch 和 API 版本低于 P 的设备实现了自己的 notch API。您可以从设备指定文档中查阅 API。

此外,我在官方文档中没有看到 DisplayCutoutCompat 实例的创建,但您可以按如下方式创建 DisplayCutout:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            DisplayCutout displayCutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
}

关于android - 如何处理低于 28 的 android API 中的缺口(显示切口)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51743622/

相关文章:

android - 为什么 Google Pay 在我的应用程序安装后停止工作?

android - 如何获取 DisplayCutoutCompat 的实例

Android Pie 9.0 将用户带到通知中心

c# - Array Adapter 重载方法

android - 使用 Dagger、Room 和 LiveData 时调试数据绑定(bind)错误

android - 应用程序 :srcCompat in xml 的 InflateException

android - 在 Android 中使用 Fragment 导致 VM 关闭

java - Android appcompat_v7错误

java - 更改lib源代码而不破坏它

Android Studio - 调试 android 应用程序时在哪里可以看到调用堆栈?