HarmonyOS NEXT API12中 windowStage.getMainWindowSync().setWindowLayoutFullScreen改成了什么

发布于 1周前 作者 itying888 最后一次编辑是 5天前 来自 分享

以前的Harmonyos中设置全屏状态栏可以使用 windowStage.getMainWindowSync().setWindowLayoutFullScreen,但是HarmonyOS NEXT API12中废弃了这个方法

 windowStage.getMainWindowSync().setWindowLayoutFullScreen(true, (err) => {
      if (err.code) {
        console.error('Failed to enable the full-screen mode. Cause: ' + JSON.stringify(err));
        return;
      }
      //设置状态栏透明背景
      windowStage.getMainWindowSync().setWindowSystemBarEnable(['status']).then(() => {
        const systemBarProperties: window.SystemBarProperties = {
          statusBarColor: '#00000000'
        };
        //设置窗口内导航栏、状态栏的属性
        windowStage.getMainWindowSync().setWindowSystemBarProperties(systemBarProperties)
          .then(() => {
            console.info('Succeeded in setting the system bar properties.');
          }).catch((err:object) => {
          console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err));
        });
      })
      console.info('Succeeded in enabling the full-screen mode.');
    })

请问HarmonyOS NEXT API12中setWindowLayoutFullScreen改成了什么

可以参考下面代码:

//参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5
    // 沉浸式状态栏
    let windowClass: window.Window | undefined = undefined;
    windowStage.getMainWindow((err: BusinessError, data) => {
      windowClass=data
      let promise = windowClass.setWindowLayoutFullScreen(true);
      promise.then(() => {
        //设置状态栏透明背景
        windowStage.getMainWindowSync().setWindowSystemBarEnable(['status']).then(() => {
          const systemBarProperties: window.SystemBarProperties = {
            statusBarColor: '#00000000'
          };
          //设置窗口内导航栏、状态栏的属性
          windowStage.getMainWindowSync().setWindowSystemBarProperties(systemBarProperties)
            .then(() => {
              console.info('Succeeded in setting the system bar properties.');
            }).catch((err:object) => {
            console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err));
          });
        })
      }).catch((err: BusinessError) => {
        console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`);
      });
    })
回到顶部