#鸿蒙学习大百科#如何给popup气泡添加按钮并监听其点击事件?

如何给popup气泡添加按钮并监听其点击事件?

HarmonyOS
2024-10-25 10:06:10
763浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
被窝终结者
import { promptAction } from '@kit.ArkUI'

@Entry
@Component
struct Index {
  @State isShowPop: boolean = false
  build() {
    Column() {
      Button("气泡提示")
        .onClick(() => {
          this.isShowPop = true
        })//设置placement为Top,气泡显示在button上方
        .bindPopup(this.isShowPop, {
          message: "Hello HarmonyOS", placement: Placement.Top,
          primaryButton: {
            value: "确认", action: () => {
              this.isShowPop = false
              promptAction.showToast({message:"点击了确认按钮"})
            }
          },
          secondaryButton:{
            value:"取消",
            action:()=>{
              this.isShowPop = false
              promptAction.showToast({message:"点击了取消按钮"})
            }
          }
        })

    }
    .width('100%')
    .height('100%')
    .justifyContent(FlexAlign.Center)
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
分享
微博
QQ
微信
回复
2024-10-25 17:34:56


相关问题