getWindowAvoidArea可以获取获取安全区域高度;如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。参考地址:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5\#getwindowavoidarea9参考demo:windowStage.loadContent('pages/Index', (err, data) => { if (err.code) { hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); return; } let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口 let topAvoidArea = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM) let bottomAvoidArea = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR) let bottomRectHeight = px2vp(bottomAvoidArea.bottomRect.height) let topRectHeight = px2vp(topAvoidArea.topRect.height) AppStorage.setOrCreate('bottomRectHeight',bottomRectHeight) AppStorage.setOrCreate('topRectHeight',topRectHeight) let isLayoutFullScreen = true; windowClass.setWindowLayoutFullScreen(isLayoutFullScreen) .then(() => { console.info('Succeeded in setting the window layout to full-screen mode.'); }) .catch((err: BusinessError) => { console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); }); hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); });需要在WindowStageCreate生命周期中的loadContent之后获取;获取到的是高度单位是vp
getWindowAvoidArea可以获取获取安全区域高度;如系统栏区域、刘海屏区域、手势区域、软键盘区域等与窗口内容重叠时,需要窗口内容避让的区域。
参考地址:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5\#getwindowavoidarea9
参考demo:
需要在WindowStageCreate生命周期中的loadContent之后获取;获取到的是高度单位是vp