文档管理中心
您当前正在浏览新版开发者文档中心,目录分类和层级有所调整。点击左侧当前文档分类名称前的“☰”图标,可切换文档分类。 了解新版目录
问题处理与运维开发与测试问题应用框架开发UI框架UI界面如何在自定义弹窗中再次弹窗

如何在自定义弹窗中再次弹窗

通过openCustomDialog打开弹窗A,在弹窗A中点击按钮打开弹窗B。通过getDialogController获取PromptActionDialogController实例对象并调用close()方法关闭当前弹窗。具体可参考示例代码:

收起
自动换行
深色代码主题
复制
  1. import { ComponentContent } from '@kit.ArkUI';
  2. @Component
  3. struct DialogAComponent {
  4. build() {
  5. Column() {
  6. Column() {
  7. Text('dialog A')
  8. .fontSize(20)
  9. .fontWeight(FontWeight.Bold)
  10. }
  11. .justifyContent(FlexAlign.Center)
  12. .height(120)
  13. Row() {
  14. Text('close')
  15. .fontColor('#0A59F7')
  16. .onClick(() => {
  17. // close self.
  18. this.getDialogController()?.close();
  19. })
  20. .width('50%')
  21. .height('100%')
  22. .textAlign(TextAlign.Center)
  23. Text('open dialog B')
  24. .fontColor('#0A59F7')
  25. .onClick(() => {
  26. // Open dialog B.
  27. let uiContext = this.getUIContext();
  28. let promptAction = uiContext.getPromptAction();
  29. promptAction.openCustomDialog(new ComponentContent(uiContext, wrapBuilder(dialogBBuilder)));
  30. })
  31. .width('50%')
  32. .height('100%')
  33. .textAlign(TextAlign.Center)
  34. }
  35. .height(50)
  36. }
  37. .width(360)
  38. .borderRadius(32)
  39. .backgroundColor(Color.White)
  40. }
  41. }
  42. @Builder
  43. function dialogABuilder() {
  44. DialogAComponent()
  45. }
  46. @Component
  47. struct DialogBComponent {
  48. build() {
  49. Column() {
  50. Column() {
  51. Text('dialog B')
  52. .fontSize(20)
  53. .fontWeight(FontWeight.Bold)
  54. }
  55. .justifyContent(FlexAlign.Center)
  56. .height(120)
  57. Row() {
  58. Text('close')
  59. .fontColor('#0A59F7')
  60. .onClick(() => {
  61. // close self.
  62. this.getDialogController()?.close();
  63. })
  64. .width('50%')
  65. .height('100%')
  66. .textAlign(TextAlign.Center)
  67. }
  68. .height(50)
  69. }
  70. .width(320)
  71. .borderRadius(32)
  72. .backgroundColor(Color.White)
  73. }
  74. }
  75. @Builder
  76. function dialogBBuilder() {
  77. DialogBComponent()
  78. }
  79. @Entry
  80. @Component
  81. struct PopUpDialogAgainInCustomDialog {
  82. build() {
  83. Column() {
  84. Button('open Dialog A')
  85. .onClick(() => {
  86. // Open dialog A.
  87. let uiContext = this.getUIContext();
  88. let promptAction = uiContext.getPromptAction();
  89. promptAction.openCustomDialog(new ComponentContent(uiContext, wrapBuilder(dialogABuilder)));
  90. })
  91. }
  92. .width('100%')
  93. .height('100%')
  94. .alignItems(HorizontalAlign.Center)
  95. .justifyContent(FlexAlign.Center)
  96. }
  97. }