我需要处理凹口设备的布局。 我知道是在伊奥斯。 我可以使用 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/