【鸿蒙NEXT】设置全屏

时间:2024-04-16 07:15:15
onWindowStageCreate(windowStage: window.WindowStage): void { EntryAbility.windowStage = windowStage // Main window is created, set main page for this ability this.requestFullScreen(windowStage, this.context) 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) ?? ''); }); } private requestFullScreen(windowStage: window.WindowStage, context: Context) { try { let windowClass = windowStage.getMainWindowSync() let area = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM) if (area.topRect.height > 0) { DeviceInfoUtils.setStatusBarHeight(area.topRect.height)//存储状态栏高度 windowClass.setWindowLayoutFullScreen(true) } } catch (err) { console.error(`requestFullScreen err = ${err}`) } }