可以在EntryAbility里获取并存储,获取到的高度是px,所以用px2vp()转换为vp使用:onWindowStageCreate(windowStage: window.WindowStage) { // Main window is created, set main page for this ability hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); 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; } hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); let windowClass = windowStage.getMainWindowSync(); let statusHeight = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).topRect.height; let bottomHeight = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect.height; AppStorage.setOrCreate('bottomHeight',px2vp(bottomHeight)); AppStorage.setOrCreate('statusHeight',px2vp(statusHeight)); }); } 在需要的界面使用 AppStorage.get('bottomHeight'),AppStorage.get('statusHeight') 获取。
可以在EntryAbility里获取并存储,获取到的高度是px,所以用px2vp()转换为vp使用: