HarmonyOS 鸿蒙Next CustomDialog有更好的实现方式么
HarmonyOS 鸿蒙Next CustomDialog有更好的实现方式么
CustomDialogController有没有更好的实现方案,现在这套方案是真难用,要提前声明,连传递的参数也要提前声明?
3 回复
目前CustomDialog的规格如此,也可以使用promptAction.openCustomDialog(),来打开自定义弹窗。 https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-promptaction-0000001821000749#ZH-CN_TOPIC_0000001857916061__promptactionopencustomdialog11 demo如下:
import promptAction from '@ohos.promptAction'
let customDialogId: number = 0
@Builder
function customDialogBuilder(dialogTxt:string,index:string) {
TestDialog({ dialogTxt: dialogTxt,content:index })
}
@Component
struct TestDialog {
@State dialogTxt: string = ''
@State content: string = ''
build() {
Column() {
Text(this.dialogTxt+this.dialogTxt).fontSize(20)
Row() {
Button("确认").onClick(() => {
promptAction.closeCustomDialog(customDialogId)
})
Blank().width(50)
Button("取消").onClick(() => {
promptAction.closeCustomDialog(customDialogId)
})
}.margin({ top: 80 })
}.height(200).padding(5)
}
}
@Entry
@Component
struct Index57 {
@State message: string = '打开弹窗'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
.onClick(() => {
promptAction.openCustomDialog({
builder: customDialogBuilder.bind(this, '标题','内容')
}).then((dialogId: number) => {
customDialogId = dialogId
})
})
}
.width('100%')
}
.height('100%')
}
}
更多关于HarmonyOS 鸿蒙Next CustomDialog有更好的实现方式么的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
promptAction.showToast()、promptAction.showDialog()怎么样?
或者看看这篇帖子有没有符合你需求的:https://developer.huawei.com/consumer/cn/blog/topic/03169396227138036