HarmonyOS Next中如何解决沉浸式应用在悬浮窗场景下顶部操作栏无法操作问题?

阅读 602
1 个回答

可能沉浸式应用顶部没有避让,导致悬浮窗顶部bar与应用的顶部区域重叠,重叠区域中的按钮无法响应点击事件。

通过getWindowAvoidArea接口可获取屏幕顶部需要规避的矩阵区域topRect,获取到该值后应用可对应做布局避让。同时可通过on('avoidAreaChange')监听系统规避区域变化以进行布局的动态调整。具体可以参考顶部窗口控制条避让适配智慧多窗,示例代码如下:

@Component
export struct Question7Correct {
  private windowClass = (getContext(this) as common.UIAbilityContext).windowStage.getMainWindowSync();
  @State topSafeHeight: number = 0;
  @State windowStatus: WindowStatusType = window.WindowStatusType.FULL_SCREEN;

  aboutToAppear(): void {
    this.windowClass.setSpecificSystemBarEnabled('status', false);
    this.windowStatus = this.windowClass.getWindowStatus();

    if (this.windowStatus === window.WindowStatusType.FLOATING) {
      this.topSafeHeight = px2vp(this.windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).topRect.height);
    }

    this.windowClass.on('windowStatusChange', data => {
      if (data === window.WindowStatusType.FLOATING) {
        this.topSafeHeight =
          px2vp(this.windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).topRect.height);
      } else {
        this.topSafeHeight = 0;
      }
    })
  }

  aboutToDisappear(): void {
    this.windowClass.setSpecificSystemBarEnabled('status', true);
  }

  build() {
    // ...
  }
}

本文参与了 【 HarmonyOS NEXT 技术问答冲榜,等你来战!】欢迎正在阅读的你也加入。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进