HarmonyOS 使用promptAction.updateCustomDialog怎么更新弹窗的内容?
是能更新弹窗的位置,但是怎么更新弹窗的内容呢?代码如下:
import { BusinessError } from '@kit.BasicServicesKit';
import { ComponentContent } from '@kit.ArkUI';
@Entry
@Component
struct CustomDialogPage {
@State message: string = 'Hello World';
build() {
Row() {
Column() {
Button("click me")
.onClick(() => {
this.message = "Hello"
let uiContext = this.getUIContext();
let promptAction = uiContext.getPromptAction();
let contentNode = new ComponentContent(uiContext, wrapBuilder(buildText), new Params(this.message));
try {
promptAction.openCustomDialog(contentNode,{alignment:DialogAlignment.Top});
} catch (error) {
let message = (error as BusinessError).message;
let code = (error as BusinessError).code;
console.error(`OpenCustomDialog args error code is ${code}, message is ${message}`);
};
setTimeout(() => {
try {
this.message = "World"//我尝试更新弹窗的文案
promptAction.updateCustomDialog(contentNode, { alignment: DialogAlignment.Bottom });//并改变弹窗的位置
} catch (error) {
let message = (error as BusinessError).message;
let code = (error as BusinessError).code;
console.error(`updateCustomDialog args error code is ${code}, message is ${message}`);
};
}, 2000); //2秒后自动更新了弹窗位置,但没有更新弹窗文案
setTimeout(()=>{
promptAction.closeCustomDialog(contentNode)
},4000)//4秒后关闭弹窗
})
}
.width('100%')
.height('100%')
}
.height('100%')
}
}
class Params {
text: string = ""
constructor(text: string) {
this.text = text;
}
}
@Builder
function buildText(params: Params) {
Column() {
Text(params.text)
.fontSize(50)
.fontWeight(FontWeight.Bold)
.margin({bottom: 36})
}.backgroundColor('#FFF0F0F0')
}
HarmonyOS
赞
收藏 0
回答 1
待解决
代码如下: