HarmonyOS ContextMenu中的item点击不显示toast

import { promptAction } from '@kit.ArkUI';

@Entry
@Component
struct Index {
  @State message: string = 'Hello World';

  build() {
    Column({ space: 20 }) {
      Text("点击")
        .fontSize(50)
        .fontWeight(FontWeight.Bold)
        .onClick(() => {
          // 点击显示toast
          this.showToast()
        })

      Text("长按")
        .fontSize(50)
        .fontWeight(FontWeight.Bold)
        .bindContextMenu(this.menu(), ResponseType.LongPress)

    }
    .height('100%')
    .width('100%')
  }

  showToast() {
    promptAction.showToast({
      message: "toast"
    })
  }

  @Builder
  menu() {
    Menu() {
      MenuItem({ content: "toast" })
        .contentFontColor(Color.Red)
        .onClick(() => {
          // 期望显示toast,实际不显示
          this.showToast()
        })
    }
  }
}
  • 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.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
HarmonyOS
2024-12-24 17:45:22
1710浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

menu子窗显示的,子窗不允许弹子窗toast,可以给toast绑定一下uiContext

如下:

import { promptAction } from '@kit.ArkUI';

@Entry
@Component
struct Index {
  @State message: string = 'Hello World';

  build() {
    Column({ space: 20 }) {
      Text("点击")
        .fontSize(50)
        .fontWeight(FontWeight.Bold)
        .onClick(() => {
          // 点击显示toast
          this.showToast()
        })

      Text("长按")
        .fontSize(50)
        .fontWeight(FontWeight.Bold)
        .bindContextMenu(this.menu(), ResponseType.LongPress)

    }
    .height('100%')
    .width('100%')
  }

  showToast() {
    promptAction.showToast({
      message: "toast"
    })
  }

  @Builder
  menu() {
    Menu() {
      MenuItem({ content: "toast" })
        .contentFontColor(Color.Red)
        .onClick(() => {
          // 期望显示toast,实际不显示:修改处
          this.getUIContext().getPromptAction().showToast({
            message: "toast"
          })
        })
    }
  }
}
  • 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.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
分享
微博
QQ
微信
回复
2024-12-24 20:10:00


相关问题
HarmonyOS toast不显示问题
688浏览 • 1回复 待解决
HarmonyOS 如果显示类似Toast提示
887浏览 • 2回复 待解决
HarmonyOS CustomDialogController 不显示
1193浏览 • 1回复 待解决
HarmonyOS 应用退到后台显示toast方案
1516浏览 • 1回复 待解决
HarmonyOS webloadData不显示内容
586浏览 • 1回复 待解决
HarmonyOS RelativeContainer内控件不显示
577浏览 • 1回复 待解决
HarmonyOS 应用图标不显示
938浏览 • 1回复 待解决
HarmonyOS Web组件不显示图片
656浏览 • 1回复 待解决
HarmonyOS push通知不显示图片
602浏览 • 1回复 待解决
HarmonyOS web组件alert不显示
1809浏览 • 1回复 待解决
HarmonyOS 应用使用iconfont不显示
700浏览 • 1回复 待解决
HarmonyOS listitem数据显示效果不一致
792浏览 • 1回复 待解决