在实际生产中,进场遇到需要关闭导航栏和状态栏的需求,现分享解决办法:

开发环境

OpenHarmony 5.0.0r

代码分析

思路: launcher本身可以关闭 导航栏(实际是 公共事件,发送消息给systemUI来实控制)

systemUI中product\default\navigationBar\src\main\ets\viewmodel\NavigationBarViewModel.ts 中

  private windowSwitches(navigationBarStatusValue: string): void {
    this.isDisplay = navigationBarStatusValue == '1' ? true : false;
    if (!this.isDisplay || !this.mNavigationBarComponentData.isEnable) {
      //For gesture navigation scenarios
      //Systemui hides the navigation bar,and then notifies the launcher that it can start moving down the dock bar.
      WindowManager.hideWindow(WindowType.STATUS_BAR).then(() => {//关状态栏
      }).catch((err) => {
        Log.showError(TAG, `${NAVIGATIONBAR_HIDE_EVENT} Publish catch err: ${JSON.stringify(err)}`);
      });

      WindowManager.hideWindow(WindowType.NAVIGATION_BAR).then(() => {//关导航栏
      }).catch((err) => {
        Log.showError(TAG, `${NAVIGATIONBAR_HIDE_EVENT} Publish catch err: ${JSON.stringify(err)}`);
      });
    } else {
      WindowManager.showWindow(WindowType.STATUS_BAR).then(() => {//开状态栏
      }).catch((err) => {
      });
      WindowManager.showWindow(WindowType.NAVIGATION_BAR).then(() => {//开导航栏
      }).catch((err) => {
      });
    }
  }

代码修改

image.png

image.png

image.png

image.png

Logo

社区规范:仅讨论OpenHarmony相关问题。

更多推荐