android - 如何在Android中为Notch设备获取安全区域

标签 android ios android-layout safearealayoutguide safeareaview

我需要处理凹口设备的布局。 我知道是在伊奥斯。 我可以使用 Ios 中的安全区域来处理它。 但在android中有什么办法可以实现这一点吗?

最佳答案

为此您需要 DisplayCutout 对象 在您的 Activity 类中(在 onCreate() 中):

WindowManager.LayoutParams lp = this.getWindow().getAttributes();

lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;    

WindowInsets windowInsets = this.getWindow().getDecorView().getRootView().getRootWindowInsets();

DisplayCutout displayCutout = windowInsets.getDisplayCutout();
int bottom = displayCutout.getSafeInsetBottom()

有关此类的更多信息,您可以在这里找到: https://developer.android.com/guide/topics/display-cutout 和这里: https://blog.felgo.com/app-dev-tips-for-devices-with-edge-to-edge-screens-2020

关于android - 如何在Android中为Notch设备获取安全区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57906262/

相关文章:

android - 如何检查 View 小部件的类型?

android - 数字选择器文本颜色

java - 将设备坐标转换为世界坐标

ios - Swift 函数参数中的变量类型

android - 如何在带有 ImageView 和 TextView 的网格布局上实现点击监听器?

android - 无法在工具栏下方进行抽屉式导航

android,如何以编程方式设置单选按钮按钮的左填充?

android - 如何在 asynctask onPostExecute 上从服务器的 imageview 上显示图像?

ios - 如何在iOS中将度数转换为极坐标

ios - HLS 视频无法在模拟器和真实设备上播放