可使用promptAction.openCustomDialog自定义弹窗://Index.ets import { changeDialogBuilder, MyShowTest } from '../common/HttpUtils'import { customDialogBuilder } from './testProm'let myShowTest = new MyShowTest()@Entry@Component struct Index {@State message: string = 'Hello World'onPageShow() : void { changeDialogBuilder(customDialogBuilder.bind(this)) } build() { Row() { Column() { Text(this.message).fontSize(50).fontWeight(FontWeight.Bold).onClick(() = >{ myShowTest.showTest() }) }.width('100%') }.height('100%') } } //testProm.ets @Builder export function customDialogBuilder() { Column() { Text('正在加载中').fontSize(16) }.height(100).width(100).backgroundColor('#EEE') } //HttpUtils.ets import promptAction from '@ohos.promptAction'let myDialogBuilder: CustomBuilder; let customDialogId: number = 0 export function changeDialogBuilder(builder: CustomBuilder) { myDialogBuilder = builder } export class MyShowTest { showTest() { if (myDialogBuilder === undefined) { return } promptAction.openCustomDialog({ builder: myDialogBuilder, alignment: DialogAlignment.Center, }).then((dialogId: number) = >{ customDialogId = dialogId }) setTimeout(() = >{ promptAction.closeCustomDialog(customDialogId) }, 2000) } }
可使用promptAction.openCustomDialog自定义弹窗: