1. 设置沉浸式:win.setWindowLayoutFullScreen(true);
2. 获取状态栏的高:win.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM)以及win.on('avoidAreaChange', (data) => {})。
import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import { logger } from '@ohos/commonLib';const TAG: string = 'EntryAbility';export default class EntryAbility extends UIAbility {onCreate(want, launchParam) {logger.info(TAG, 'onCreate');}onDestroy() {logger.info(TAG, 'onDestroy');}onWindowStageCreate(windowStage: window.WindowStage) {windowStage.loadContent('pages/StartPage', (err, data) => {if (err.code) {logger.info(TAG, 'loadContent err=', JSON.stringify(err) ?? '');return;}logger.info(TAG, 'loadContent success=', JSON.stringify(data) ?? '');});}private setWindow(windowStage: window.WindowStage) {windowStage.getMainWindow().then((win: window.Window) => {win.setWindowLayoutFullScreen(true);try {const avoidArea = win.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM);if (avoidArea) {// AppStorage.SetOrCreate('statusBarHeight', avoidArea?.topRect?.height);}win.on('avoidAreaChange', (data) => {// AppStorage.SetOrCreate('statusBarHeight', data?.area?.topRect?.height);});} catch (err) {}})}
}