- 可以通过设置组件的expandSafeArea属性来获取获取UIWindow:首先,你需要获取到当前页面的UIWindow实例。
- 调用getSafeArea方法:通过UIWindow实例调用getSafeArea方法来获取安全区域的Rect对象
import ohos.aafwk.ability.AbilitySlice; import ohos.aafwk.content.Intent; import ohos.agp.window.UIWindow; import ohos.agp.utils.Rect; public class MyAbilitySlice extends AbilitySlice { @Override public void onStart(Intent intent) { super.onStart(intent); setUIContent(new SurfaceLayout(this)); UIWindow window = getUIWindow(); if (window != null) { // 获取安全区域 Rect safeArea = window.getSafeArea(); // 在这里可以使用safeArea对象,它包含了安全区域的位置和尺寸信息 // 例如,可以使用safeArea.left, safeArea.top, safeArea.right, safeArea.bottom } } }
07-11
02-17
8364

07-08
1万+
