HarmonyOS dialog展示时不占据焦点

想咨询一下页面弹出对话框,其他按钮就不能点击了,有没有什么方式弹出对话框还能对其他组件做操作

HarmonyOS
2025-01-09 15:22:05
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
put_get

您的意思是弹出弹窗之后弹窗下面的按钮无法操作么? isModal: false 即可

// xxx.ets
@CustomDialog
struct CustomDialogExample {
  controller?: CustomDialogController
  cancel: () => void = () => {
  }
  confirm: () => void = () => {
  }
  build() {
    Column() {
      Text('可展示在主窗口外的弹窗')
        .fontSize(30)
        .height(100)
      Button('点我关闭弹窗')
        .onClick(() => {
          if (this.controller != undefined) {
            this.controller.close()
          }
        })
        .margin(20)
    }
  }
}
@Entry
@Component
struct CustomDialogUser {
  dialogController: CustomDialogController | null = new CustomDialogController({
    builder: CustomDialogExample({
      cancel: ()=> { this.onCancel() },
      confirm: ()=> { this.onAccept() }
    }),
    cancel: this.existApp,
    autoCancel: true,
    onWillDismiss:(dismissDialogAction: DismissDialogAction)=> {
      console.info("reason=" + JSON.stringify(dismissDialogAction.reason))
      console.log("dialog onWillDismiss")
      if (dismissDialogAction.reason == DismissReason.PRESS_BACK) {
        dismissDialogAction.dismiss()
      }
      if (dismissDialogAction.reason == DismissReason.TOUCH_OUTSIDE) {
        dismissDialogAction.dismiss()
      }
    },
    gridCount: 4,
    showInSubWindow: true,
    isModal: false,
    customStyle: false,
    cornerRadius: 10,
    backgroundColor: Color.Green
  })
  // 在自定义组件即将析构销毁时将dialogController置空
  aboutToDisappear() {
    this.dialogController = null // 将dialogController置空
  }

  onCancel() {
    console.info('Callback when the first button is clicked')
  }

  onAccept() {
    console.info('Callback when the second button is clicked')
  }

  existApp() {
    console.info('Click the callback in the blank area')
  }

  build() {
    Column() {
      Button('click me')
        .onClick(() => {
          if (this.dialogController != null) {
            this.dialogController.open()
          }
        }).backgroundColor(0x317aff)
      Button("点击测试").margin({top: 10}).onClick(() => {
        console.log("点击测试")
      })
    }.width('100%').margin({ top: 5 })
  }
}
分享
微博
QQ
微信
回复
2025-01-09 17:36:12
相关问题
HarmonyOS Image获取焦点和失去焦点失效
220浏览 • 1回复 待解决
HarmonyOS 焦点问题
333浏览 • 1回复 待解决
HarmonyOS CustomDialog焦点
155浏览 • 1回复 待解决
HarmonyOS web再次展示,会闪一下
183浏览 • 1回复 待解决
Text多行展示,如何设置行间距?
573浏览 • 1回复 待解决
HarmonyOS Dialog相关
230浏览 • 1回复 待解决