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()
})
}
}
}
menu子窗显示的,子窗不允许弹子窗toast,可以给toast绑定一下uiContext
如下: