当前位置:   article > 正文

【鸿蒙NEXT】设置全屏

【鸿蒙NEXT】设置全屏

EntryAbility.ets

 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}`)
    }
  }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/399440
推荐阅读
相关标签
  

闽ICP备14008679号