《鸿蒙开发-答案之书》全屏设置

95 阅读1分钟
《鸿蒙开发-答案之书》全屏设置

app中某些界面是要沉浸式的,全屏就来了。但是它的全屏设置有点坑,它只能设置整个app的,其中一个page改变了全屏变不全屏,会影响到其他界面。因为它本质是一个Activity,很多page。

直接上代码:

  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/SplashPage', (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) ?? '');
    // });

    windowStage.loadContent('pages/SplashPage', (err, data) => {
      if (err.code) {
        return;
      }

      let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口
      // 1. 设置窗口全屏
      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));
        });

      // 顶部状态栏颜色,这样就算系统是深色模式,也显示正常
      const systemBarProperties: window.SystemBarProperties = {
        statusBarColor: "#0000000000",
        statusBarContentColor: "#000000",
        isStatusBarLightIcon: true
      }
      windowClass.setWindowSystemBarProperties(systemBarProperties, (err, result) => {
        // LogUtils.debug("设置状态栏结果码", `${err.code}`)
        // if (err.code == 0) {
        //   LogUtils.debug("状态栏设置成功")
        // } else {
        //   LogUtils.debug("状态栏设置失败", `${err.message}`)
        // }
      })

    });

  }

有鸿蒙开发bug或者需求可私信我,我每天都看私信的