解决方案:可使用@ohos.promptAction (弹窗),示例代码:import promptAction from '@ohos.promptAction'; import { BusinessError } from '@ohos.base'; function showDialog() { try { promptAction.showDialog({ title: 'showDialog Title Info', message: 'Message Info', isModal: true, showInSubWindow: true, alignment: DialogAlignment.Center, buttons: [ { text: 'button1', color: '#000000' }, ] }, (err, data) => { if (err) { console.info('showDialog err: ' + err); return; } console.info('showDialog success callback, click button: ' + data.index); }); } catch (error) { let message = (error as BusinessError).message let code = (error as BusinessError).code console.error(`showDialog args error code is ${code}, message is ${message}`); }; } @Entry @Component struct Index { @State message: string = 'Hello World'; build() { Row() { Column() { Text(this.message) .fontSize(50) .fontWeight(FontWeight.Bold) Button('showDialog ', { stateEffect: true, type: ButtonType.Capsule }) .width('80%') .height(40) .margin(20) .onClick(() => { showDialog() }) } .width('100%') } .height('100%') } }
解决方案:
可使用@ohos.promptAction (弹窗),示例代码: