如何以编程方式检测 Mi 设备中的全屏手势模式

How to detect full screen gesture mode in Mi devices programmatically

我正在编写一个 Android 应用程序,需要计算屏幕高度才能正确显示内容。但是当切换到全屏手势模式时,我在 Mi 设备 (Mi 9 SE) 中获得的高度不正确。 如何获取屏幕的实际高度,或者查看用户是否在小米设备中开启了全屏手势模式?

我已经尝试了这些建议。

  1. How to detect full screen gesture mode in android Q
  2. Android: detect navigation bar visibility
  3. Check for navigation bar

经过搜索和试验,我找到了唯一的解决方案:How to detect full screen gesture mode in android Q

我不必使用 ViewCompat.setOnApplyWindowInsetsListener() 函数,只需为当前上下文创建一个 WindowInsets 实例,然后检查每个边的 getSystemGestureInsets()。这就是我实现制作 React Native 的原生模块的方式。

如果您需要一个侦听器来检测每个更改,上面的解决方案在 Android 应用程序上运行良好。如果你想要 React Native 的这个监听器,你可能想找到另一种方法,因为我还没有让它工作。

一个非常简单的答案: 不要使用 DisplayMetrics。只需让任何视图占据屏幕的整个宽度和高度 (MATCH_PARENT),然后获取它的尺寸,它就会给出准确的数字。