• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.promptAction (Prompt)
2
3The **PromptAction** module provides APIs for creating and showing toasts, dialog boxes, and action menus.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8>
9> This module cannot be used in the file declaration of the [UIAbility](../apis-ability-kit/js-apis-app-ability-uiAbility.md). In other words, the APIs of this module can be used only after a component instance is created; they cannot be called in the lifecycle of the UIAbility.
10>
11> The functionality of this module depends on UI context. This means that the APIs of this module cannot be used where the UI context is unclear. For details, see [UIContext](js-apis-arkui-UIContext.md#uicontext). Except for UI-less scenarios<!--Del--> such as [ServiceExtension](../../application-models/serviceextensionability.md)<!--DelEnd-->, it is recommended that you use the dialog APIs provided by **UIContext**.
12>
13> Since API version 10, you can use the [getPromptAction](js-apis-arkui-UIContext.md#getpromptaction) API in [UIContext](js-apis-arkui-UIContext.md#uicontext) to obtain the [PromptAction](js-apis-arkui-UIContext.md#promptaction) object associated with the current UI context.
14
15## Modules to Import
16
17```ts
18import { promptAction } from '@kit.ArkUI';
19```
20
21## promptAction.showToast
22
23showToast(options: ShowToastOptions): void
24
25Shows a toast.
26
27**Atomic service API**: This API can be used in atomic services since API version 11.
28
29**System capability**: SystemCapability.ArkUI.ArkUI.Full
30
31**Parameters**
32
33| Name    | Type                                   | Mandatory  | Description     |
34| ------- | ------------------------------------- | ---- | ------- |
35| options | [ShowToastOptions](#showtoastoptions) | Yes   | Toast options.|
36
37**Error codes**
38
39For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
40
41| ID  | Error Message|
42| --------- | ------- |
43| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
44| 100001    | Internal error. |
45
46**Example**
47
48```ts
49import { promptAction } from '@kit.ArkUI'
50import { BusinessError } from '@kit.BasicServicesKit';
51
52@Entry
53@Component
54struct toastExample {
55  build() {
56    Column() {
57      Button('Show toast').fontSize(20)
58        .onClick(() => {
59          try {
60            promptAction.showToast({
61              message: 'Hello World',
62              duration: 2000
63            });
64          } catch (error) {
65            let message = (error as BusinessError).message
66            let code = (error as BusinessError).code
67            console.error(`showToast args error code is ${code}, message is ${message}`);
68          };
69        })
70    }.height('100%').width('100%').justifyContent(FlexAlign.Center)
71  }
72}
73```
74Below is a toast in API version 11 and earlier versions.
75
76![en-us_image_0001](figures/toast-api11.gif)
77
78Below is a toast in API version 12 and later versions.
79
80![en-us_image_0001](figures/toast-api12.gif)
81
82## promptAction.openToast<sup>18+</sup>
83
84openToast(options: ShowToastOptions): Promise&lt;number&gt;
85
86Opens a toast. This API returns the toast ID.
87
88**Atomic service API**: This API can be used in atomic services since API version 18.
89
90**System capability**: SystemCapability.ArkUI.ArkUI.Full
91
92**Parameters**
93
94| Name | Type                                                        | Mandatory| Description          |
95| ------- | ------------------------------------------------------------ | ---- | -------------- |
96| options | [ShowToastOptions](#showtoastoptions) | Yes  | Toast options.|
97
98**Return value**
99
100| Type            | Description                                |
101| ---------------- | ------------------------------------ |
102| Promise&lt;number&gt; | ID of the toast, which is required in **closeToast**.|
103
104**Error codes**
105
106For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
107
108| ID| Error Message                                                    |
109| -------- | ------------------------------------------------------------ |
110| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. |
111| 100001   | Internal error.                                              |
112
113**Example**
114
115```ts
116import { promptAction } from '@kit.ArkUI';
117import { BusinessError } from '@kit.BasicServicesKit';
118
119@Entry
120@Component
121struct toastExample {
122  @State toastId: number = 0;
123
124  build() {
125    Column() {
126      Button('Open Toast')
127        .height(100)
128        .type(ButtonType.Capsule)
129        .onClick(() => {
130          promptAction.openToast({
131            message: 'Toast Message',
132            duration: 10000,
133          }).then((toastId: number) => {
134            this.toastId = toastId;
135          })
136            .catch((error: BusinessError) => {
137              console.error(`openToast error code is ${error.code}, message is ${error.message}`)
138            })
139        })
140      Blank().height(50);
141      Button('Close Toast')
142        .height(100)
143        .type(ButtonType.Capsule)
144        .onClick(() => {
145          try {
146            promptAction.closeToast(this.toastId);
147          } catch (error) {
148            let message = (error as BusinessError).message;
149            let code = (error as BusinessError).code;
150            console.error(`CloseToast error code is ${code}, message is ${message}`);
151          };
152        })
153    }.height('100%').width('100%').justifyContent(FlexAlign.Center)
154  }
155}
156```
157
158![toast-openclose](figures/toast-openclose.gif)
159
160## promptAction.closeToast<sup>18+</sup>
161
162closeToast(toastId: number): void
163
164Closes a toast.
165
166**Atomic service API**: This API can be used in atomic services since API version 18.
167
168**System capability**: SystemCapability.ArkUI.ArkUI.Full
169
170**Parameters**
171
172| Name | Type  | Mandatory| Description                         |
173| ------- | ------ | ---- | ----------------------------- |
174| toastId | number | Yes  | ID of the toast to close, which is returned by **openToast**.|
175
176**Error codes**
177
178For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
179
180| ID| Error Message                                                    |
181| -------- | ------------------------------------------------------------ |
182| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. |
183| 100001   | Internal error.                                              |
184
185**Example**
186
187See the example for [promptAction.openToaset18](#promptactionopentoast18).
188
189## promptAction.showDialog
190
191showDialog(options: ShowDialogOptions): Promise&lt;ShowDialogSuccessResponse&gt;
192
193Shows a dialog box. This API uses a promise to return the result asynchronously.
194
195**Atomic service API**: This API can be used in atomic services since API version 11.
196
197**System capability**: SystemCapability.ArkUI.ArkUI.Full
198
199**Parameters**
200
201| Name    | Type                                     | Mandatory  | Description    |
202| ------- | --------------------------------------- | ---- | ------ |
203| options | [ShowDialogOptions](#showdialogoptions) | Yes   | Dialog box options.|
204
205**Return value**
206
207| Type                                      | Description      |
208| ---------------------------------------- | -------- |
209| Promise&lt;[ShowDialogSuccessResponse](#showdialogsuccessresponse)&gt; | Promise used to return the dialog box response result.|
210
211**Error codes**
212
213For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
214
215| ID  | Error Message|
216| --------- | ------- |
217| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
218| 100001    | Internal error. |
219
220**Example**
221
222```ts
223import { promptAction } from '@kit.ArkUI'
224
225promptAction.showDialog({
226  title: 'Title Info',
227  message: 'Message Info',
228  buttons: [
229    {
230      text: 'button1',
231      color: '#000000'
232    },
233    {
234      text: 'button2',
235      color: '#000000'
236    }
237  ],
238})
239  .then(data => {
240    console.info('showDialog success, click button: ' + data.index);
241  })
242  .catch((err: Error) => {
243    console.info('showDialog error: ' + err);
244  })
245```
246
247![en-us_image_0002](figures/en-us_image_0002.gif)
248
249## promptAction.showDialog
250
251showDialog(options: ShowDialogOptions, callback: AsyncCallback&lt;ShowDialogSuccessResponse&gt;):void
252
253Shows a dialog box. This API uses an asynchronous callback to return the result.
254
255**Atomic service API**: This API can be used in atomic services since API version 11.
256
257**System capability**: SystemCapability.ArkUI.ArkUI.Full
258
259**Parameters**
260
261| Name     | Type                                      | Mandatory  | Description          |
262| -------- | ---------------------------------------- | ---- | ------------ |
263| options  | [ShowDialogOptions](#showdialogoptions)  | Yes   | Dialog box options.|
264| callback | AsyncCallback&lt;[ShowDialogSuccessResponse](#showdialogsuccessresponse)&gt; | Yes   | Callback used to return the dialog box response result.  |
265
266**Error codes**
267
268For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
269
270| ID  | Error Message|
271| --------- | ------- |
272| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
273| 100001    | Internal error. |
274
275**Example**
276
277```ts
278import { promptAction } from '@kit.ArkUI';
279import { BusinessError } from '@kit.BasicServicesKit';
280
281try {
282  promptAction.showDialog({
283    title: 'showDialog Title Info',
284    message: 'Message Info',
285    buttons: [
286      {
287        text: 'button1',
288        color: '#000000'
289      },
290      {
291        text: 'button2',
292        color: '#000000'
293      }
294    ]
295  }, (err, data) => {
296    if (err) {
297      console.info('showDialog err: ' + err);
298      return;
299    }
300    console.info('showDialog success callback, click button: ' + data.index);
301  });
302} catch (error) {
303  let message = (error as BusinessError).message
304  let code = (error as BusinessError).code
305  console.error(`showDialog args error code is ${code}, message is ${message}`);
306};
307```
308
309![en-us_image_0004](figures/en-us_image_0004.gif)
310
311When the **showInSubWindow** attribute is set to **true**, the toast can be displayed outside the window.
312
313```ts
314import { promptAction } from '@kit.ArkUI';
315import { BusinessError } from '@kit.BasicServicesKit';
316
317try {
318  promptAction.showDialog({
319    title: 'showDialog Title Info',
320    message: 'Message Info',
321    isModal: true,
322    showInSubWindow: true,
323    buttons: [
324      {
325        text: 'button1',
326        color: '#000000'
327      },
328      {
329        text: 'button2',
330        color: '#000000'
331      }
332    ]
333  }, (err, data) => {
334    if (err) {
335      console.info('showDialog err: ' + err);
336      return;
337    }
338    console.info('showDialog success callback, click button: ' + data.index);
339  });
340} catch (error) {
341  let message = (error as BusinessError).message
342  let code = (error as BusinessError).code
343  console.error(`showDialog args error code is ${code}, message is ${message}`);
344};
345```
346
347![en-us_image_0002_showinsubwindow](figures/en-us_image_0002_showinsubwindow.jpg)
348
349
350
351## promptAction.showActionMenu
352
353showActionMenu(options: ActionMenuOptions, callback: AsyncCallback&lt;ActionMenuSuccessResponse&gt;):void
354
355Shows an action menu. This API uses a callback to return the result asynchronously.
356
357**Atomic service API**: This API can be used in atomic services since API version 11.
358
359**System capability**: SystemCapability.ArkUI.ArkUI.Full
360
361**Parameters**
362
363| Name     | Type                                      | Mandatory  | Description       |
364| -------- | ---------------------------------------- | ---- | --------- |
365| options  | [ActionMenuOptions](#actionmenuoptions)  | Yes   | Action menu options.  |
366| callback | AsyncCallback&lt;[ActionMenuSuccessResponse](#actionmenusuccessresponse)> | Yes   | Callback used to return the action menu response result.|
367
368**Error codes**
369
370For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
371
372| ID  | Error Message|
373| --------- | ------- |
374| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
375| 100001    | Internal error. |
376
377**Example**
378
379```ts
380import { promptAction } from '@kit.ArkUI';
381import { BusinessError } from '@kit.BasicServicesKit';
382
383try {
384  promptAction.showActionMenu({
385    title: 'Title Info',
386    buttons: [
387      {
388        text: 'item1',
389        color: '#666666'
390      },
391      {
392        text: 'item2',
393        color: '#000000'
394      },
395    ]
396  }, (err, data) => {
397    if (err) {
398      console.info('showActionMenu err: ' + err);
399      return;
400    }
401    console.info('showActionMenu success callback, click button: ' + data.index);
402  })
403} catch (error) {
404  let message = (error as BusinessError).message
405  let code = (error as BusinessError).code
406  console.error(`showActionMenu args error code is ${code}, message is ${message}`);
407};
408```
409
410![en-us_image_0005](figures/en-us_image_0005.gif)
411
412## promptAction.showActionMenu
413
414showActionMenu(options: ActionMenuOptions): Promise&lt;ActionMenuSuccessResponse&gt;
415
416Shows an action menu. This API uses a promise to return the result asynchronously.
417
418**Atomic service API**: This API can be used in atomic services since API version 11.
419
420**System capability**: SystemCapability.ArkUI.ArkUI.Full
421
422**Parameters**
423
424| Name    | Type                                     | Mandatory  | Description     |
425| ------- | --------------------------------------- | ---- | ------- |
426| options | [ActionMenuOptions](#actionmenuoptions) | Yes   | Action menu options.|
427
428**Return value**
429
430| Type                                      | Description     |
431| ---------------------------------------- | ------- |
432| Promise&lt;[ActionMenuSuccessResponse](#actionmenusuccessresponse)&gt; | Promise used to return the action menu response result.|
433
434**Error codes**
435
436For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
437
438| ID  | Error Message|
439| --------- | ------- |
440| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
441| 100001    | Internal error. |
442
443**Example**
444
445```ts
446import { promptAction } from '@kit.ArkUI';
447
448promptAction.showActionMenu({
449  title: 'showActionMenu Title Info',
450  buttons: [
451    {
452      text: 'item1',
453      color: '#666666'
454    },
455    {
456      text: 'item2',
457      color: '#000000'
458    },
459  ]
460})
461  .then(data => {
462    console.info('showActionMenu success, click button: ' + data.index);
463  })
464  .catch((err: Error) => {
465    console.info('showActionMenu error: ' + err);
466  })
467```
468
469![en-us_image_0006](figures/en-us_image_0006.gif)
470
471## promptAction.openCustomDialog<sup>11+</sup>
472
473openCustomDialog(options: CustomDialogOptions): Promise&lt;number&gt;
474
475Opens a custom dialog box.
476
477<!--Del-->This API cannot be used in **ServiceExtension**.<!--DelEnd-->
478
479**isModal = true** and **showInSubWindow = true** cannot be used at the same time.
480
481By default, the width of the dialog box in portrait mode is the width of the window where it is located minus the left and right margins (40 vp for 2-in-1 devices and 16 vp for other devices), and the maximum width is 400 vp.
482
483**Atomic service API**: This API can be used in atomic services since API version 12.
484
485**System capability**: SystemCapability.ArkUI.ArkUI.Full
486
487**Parameters**
488
489| Name | Type                                         | Mandatory| Description              |
490| ------- | --------------------------------------------- | ---- | ------------------ |
491| options | [CustomDialogOptions](#customdialogoptions11) | Yes  | Content of the custom dialog box.|
492
493**Return value**
494
495| Type                 | Description                                 |
496| --------------------- | ------------------------------------- |
497| Promise&lt;number&gt; | ID of the custom dialog box, which can be used in **closeCustomDialog**.|
498
499**Error codes**
500
501For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
502
503| ID| Error Message                          |
504| -------- | ---------------------------------- |
505| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
506| 100001   | Internal error. |
507
508**Example**
509
510```ts
511import { promptAction } from '@kit.ArkUI'
512import { BusinessError } from '@kit.BasicServicesKit'
513
514@Entry
515@Component
516struct Index {
517  private customDialogComponentId: number = 0
518
519  @Builder
520  customDialogComponent() {
521    Column() {
522      Text('Dialog box').fontSize(30)
523      Row({ space: 50 }) {
524        Button("OK").onClick(() => {
525          try {
526            promptAction.closeCustomDialog(this.customDialogComponentId)
527          } catch (error) {
528            let message = (error as BusinessError).message;
529            let code = (error as BusinessError).code;
530            console.error(`closeCustomDialog error code is ${code}, message is ${message}`);
531          }
532        })
533        Button("Cancel").onClick(() => {
534          try {
535            promptAction.closeCustomDialog(this.customDialogComponentId)
536          } catch (error) {
537            let message = (error as BusinessError).message;
538            let code = (error as BusinessError).code;
539            console.error(`closeCustomDialog error code is ${code}, message is ${message}`);
540          }
541        })
542      }
543    }.height(200).padding(5).justifyContent(FlexAlign.SpaceBetween)
544  }
545
546  build() {
547    Row() {
548      Column({ space: 20 }) {
549        Text('In-component dialog box')
550          .fontSize(30)
551          .onClick(() => {
552            promptAction.openCustomDialog({
553              builder: () => {
554                this.customDialogComponent()
555              },
556              onWillDismiss: (dismissDialogAction: DismissDialogAction) => {
557                console.info("reason" + JSON.stringify(dismissDialogAction.reason))
558                console.log("dialog onWillDismiss")
559                if (dismissDialogAction.reason == DismissReason.PRESS_BACK) {
560                  dismissDialogAction.dismiss()
561                }
562                if (dismissDialogAction.reason == DismissReason.TOUCH_OUTSIDE) {
563                  dismissDialogAction.dismiss()
564                }
565              }
566            }).then((dialogId: number) => {
567              this.customDialogComponentId = dialogId
568            })
569              .catch((error: BusinessError) => {
570                console.error(`openCustomDialog error code is ${error.code}, message is ${error.message}`)
571              })
572          })
573      }
574      .width('100%')
575    }
576    .height('100%')
577  }
578}
579
580```
581This example demonstrates how to set styles of a dialog box, including the width, height, background color, and shadow.
582```ts
583import { promptAction, LevelMode, ImmersiveMode } from '@kit.ArkUI'
584
585let customDialogId: number = 0
586
587@Builder
588function customDialogBuilder() {
589  Column() {
590    Text('Custom dialog Message').fontSize(10)
591    Row() {
592      Button("OK").onClick(() => {
593        promptAction.closeCustomDialog(customDialogId)
594      })
595      Blank().width(50)
596      Button("Cancel").onClick(() => {
597        promptAction.closeCustomDialog(customDialogId)
598      })
599    }
600  }
601}
602
603@Entry
604@Component
605struct Index {
606  @State message: string = 'Hello World'
607
608  @Builder
609  customDialogComponent() {
610    customDialogBuilder()
611  }
612
613  build() {
614    Row() {
615      Column() {
616        Text(this.message).id("test_text")
617          .fontSize(50)
618          .fontWeight(FontWeight.Bold)
619          .onClick(() => {
620            const node: FrameNode | null = this.getUIContext().getFrameNodeById("test_text") || null;
621            promptAction.openCustomDialog({
622              builder: () => {
623                this.customDialogComponent()
624              },
625              keyboardAvoidMode: KeyboardAvoidMode.NONE,
626              showInSubWindow: false,
627              offset: { dx: 5, dy: 5 },
628              backgroundColor: 0xd9ffffff,
629              cornerRadius: 20,
630              width: '80%',
631              height: 200,
632              borderWidth: 1,
633              borderStyle: BorderStyle.Dashed, // borderStyle must be used with borderWidth in pairs.
634              borderColor: Color.Blue, // borderColor must be used with borderWidth in pairs.
635              shadow: ({
636                radius: 20,
637                color: Color.Grey,
638                offsetX: 50,
639                offsetY: 0
640              }),
641              levelMode: LevelMode.EMBEDDED,
642              levelUniqueId: node?.getUniqueId(),
643              immersiveMode: ImmersiveMode.DEFAULT,
644            }).then((dialogId: number) => {
645              customDialogId = dialogId
646            })
647          })
648      }
649      .width('100%')
650    }
651    .height('100%')
652  }
653}
654```
655![en-us_image_0007](figures/en-us_image_0007.gif)
656
657This example shows how to implement a dialog box on a page.
658```ts
659// Index.ets
660import { promptAction, LevelMode, ImmersiveMode, router } from '@kit.ArkUI'
661
662let customDialogId: number = 0
663
664@Builder
665function customDialogBuilder() {
666  Column() {
667    Text('Custom dialog Message').fontSize(10).height(100)
668    Row() {
669      Button("Next").onClick(() => {
670        router.pushUrl({url: 'pages/Next'})
671      })
672      Blank().width(50)
673      Button("Close").onClick(() => {
674        promptAction.closeCustomDialog(customDialogId)
675      })
676    }
677  }.padding(20)
678}
679
680@Entry
681@Component
682struct Index {
683  @State message: string = 'Hello World'
684
685  @Builder
686  customDialogComponent() {
687    customDialogBuilder()
688  }
689
690  build() {
691    Row() {
692      Column() {
693        Text(this.message).id("test_text")
694          .fontSize(50)
695          .fontWeight(FontWeight.Bold)
696          .onClick(() => {
697            const node: FrameNode | null = this.getUIContext().getFrameNodeById("test_text") || null;
698            promptAction.openCustomDialog({
699              builder: () => {
700                this.customDialogComponent()
701              },
702              levelMode: LevelMode.EMBEDDED,
703              levelUniqueId: node?.getUniqueId(),
704              immersiveMode: ImmersiveMode.DEFAULT,
705            }).then((dialogId: number) => {
706              customDialogId = dialogId
707            })
708          })
709      }
710      .width('100%')
711    }
712    .height('100%')
713  }
714}
715```
716```ts
717// Next.ets
718import { router } from '@kit.ArkUI'
719
720@Entry
721@Component
722struct Next {
723  @State message: string = 'Back'
724
725  build() {
726    Row() {
727      Column() {
728        Button(this.message)
729          .fontSize(50)
730          .fontWeight(FontWeight.Bold)
731          .onClick(() => {
732            router.back()
733          })
734      }
735      .width('100%')
736    }
737    .height('100%')
738  }
739}
740```
741![embedded_dialog](figures/embedded_dialog.gif)
742
743## promptAction.closeCustomDialog<sup>11+</sup>
744
745closeCustomDialog(dialogId: number): void
746
747Closes the specified custom dialog box.
748
749**Atomic service API**: This API can be used in atomic services since API version 12.
750
751**System capability**: SystemCapability.ArkUI.ArkUI.Full
752
753**Parameters**
754
755| Name  | Type  | Mandatory| Description                            |
756| -------- | ------ | ---- | -------------------------------- |
757| dialogId | number | Yes  | ID of the custom dialog box to close. It is returned from **openCustomDialog**.|
758
759**Error codes**
760
761For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
762
763| ID| Error Message                          |
764| -------- | ---------------------------------- |
765| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
766| 100001   | Internal error. |
767
768**Example**
769
770See the example of [promptAction.openCustomDialog](#promptactionopencustomdialog11).
771
772## ShowToastOptions
773
774Describes the options for showing the toast.
775
776**System capability**: SystemCapability.ArkUI.ArkUI.Full
777
778| Name                   | Type                                                        | Mandatory| Description                                                        |
779| ----------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
780| message                 | string \| [Resource](arkui-ts/ts-types.md#resource) | Yes  | Text to display.<br>**NOTE**<br>The default font is **'Harmony Sans'**. Other fonts are not supported.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
781| duration                | number                                                       | No  | Duration that the toast will remain on the screen. The default value is 1500 ms. The value range is 1500 ms to 10000 ms. If a value less than 1500 ms is set, the default value is used. If the value greater than 10000 ms is set, the upper limit 10000 ms is used.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
782| bottom                  | string \| number                                   | No  | Distance from the bottom of the toast to the navigation bar. In **ToastShowMode.TOP_MOST** mode, if the soft keyboard is raised and the **bottom** value is too small, the toast will automatically avoid being blocked by the soft keyboard by moving up 80 vp above it. In **ToastShowMode.DEFAULT** mode, the toast will move up by the height of the soft keyboard.<br>Default value: **80vp**<br>**NOTE**<br>When there is no navigation bar at the bottom, **bottom** sets the distance from the bottom of the toast to the bottom of the window.<br>If the **alignment** property is set, **bottom** will not take effect.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
783| showMode<sup>11+</sup>  | [ToastShowMode](#toastshowmode11)                            | No  | Whether to show the toast above the application.<br>Default value: **ToastShowMode.DEFAULT**, which means to show the toast in the application.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
784| alignment<sup>12+</sup> | [Alignment](arkui-ts/ts-appendix-enums.md#alignment)         | No  | Alignment mode.<br>Default value: **undefined**, indicating bottom start<br>**Atomic service API**: This API can be used in atomic services since API version 12.        |
785| offset<sup>12+</sup>    | [Offset](arkui-ts/ts-types.md#offset)                        | No  | Offset in the specified alignment mode.<br>Default value: **{ dx: 0, dy: 0 }**, indicating no offset<br>**NOTE**<br>Only values in the px unit are accepted. To use the vp unit, convert them to px first.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
786| backgroundColor<sup>12+</sup>    | [ResourceColor](arkui-ts/ts-types.md#resourcecolor) | No  | Background color of the toast.<br>Default value: **Color.Transparent**<br>**NOTE**<br>When **backgroundColor** is set to a non-transparent color, **backgroundBlurStyle** must be set to **BlurStyle.NONE**; otherwise, the color display may not meet the expected effect.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
787| textColor<sup>12+</sup>    | [ResourceColor](arkui-ts/ts-types.md#resourcecolor) | No  | Font color of the toast.<br>Default value: **Color.Black**<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
788| backgroundBlurStyle<sup>12+</sup>    | [BlurStyle](arkui-ts/ts-universal-attributes-background.md#blurstyle9) | No  | Background blur style of the toast.<br>Default value: **BlurStyle.COMPONENT_ULTRA_THICK**<br>**NOTE**<br>Setting this parameter to **BlurStyle.NONE** disables the background blur. When **backgroundBlurStyle** is set to a value other than **NONE**, do not set **backgroundColor**. If you do, the color display may not produce the expected visual effect.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
789| shadow<sup>12+</sup>    | [ShadowOptions](arkui-ts/ts-universal-attributes-image-effect.md#shadowoptions) \| [ShadowStyle](arkui-ts/ts-universal-attributes-image-effect.md#shadowstyle10) | No  | Background shadow of the toast.<br>Default value: **ShadowStyle.OUTER_DEFAULT_MD**<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
790| enableHoverMode<sup>14+</sup>    | boolean                       | No  | Whether to enable the hover state.<br>Default value: **false**, meaning not to enable the hover state.<br>**Atomic service API**: This API can be used in atomic services since API version 14.|
791| hoverModeArea<sup>14+</sup> | [HoverModeAreaType](arkui-ts/ts-appendix-enums.md#hovermodeareatype14)         | No  | Display area of the toast in the hover state.<br>Default value: **HoverModeAreaType.BOTTOM_SCREEN**, indicating that the toast is displayed in the lower half screen<br>**Atomic service API**: This API can be used in atomic services since API version 14.        |
792
793## ToastShowMode<sup>11+</sup>
794
795Describes the mode in which the toast is shown.
796
797**Atomic service API**: This API can be used in atomic services since API version 12.
798
799**System capability**: SystemCapability.ArkUI.ArkUI.Full
800
801| Name    | Value  | Description                  |
802| -------- | ---- | ---------------------- |
803| DEFAULT  | 0    | The toast is shown within the application.  |
804| TOP_MOST | 1    | The toast is shown above the application.|
805
806## ShowDialogOptions
807
808Describes the options for showing the dialog box.
809
810**System capability**: SystemCapability.ArkUI.ArkUI.Full
811
812| Name                             | Type                                                        | Mandatory| Description                                                        |
813| --------------------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
814| title                             | string \| [Resource](arkui-ts/ts-types.md#resource) | No  | Title of the dialog box.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
815| message                           | string \| [Resource](arkui-ts/ts-types.md#resource) | No  | Text body.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
816| buttons                           | Array&lt;[Button](#button)&gt;                               | No  | Array of buttons in the dialog box. The array structure is {text:'button', color: '\#666666'}. More than one button is supported.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
817| alignment<sup>10+</sup>           | [DialogAlignment](arkui-ts/ts-methods-alert-dialog-box.md#dialogalignment) | No  | Alignment mode of the dialog box in the vertical direction.<br>Default value: **DialogAlignment.Default**<br>**NOTE**<br>If **showInSubWindow** is set to **true** in **UIExtension**, the dialog box is aligned with the host window based on **UIExtension**.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
818| offset<sup>10+</sup>              | [Offset](arkui-ts/ts-types.md#offset)                        | No  | Offset of the dialog box based on the **alignment** settings.<br>Default value: **{ dx: 0 , dy: 0 }**<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
819| maskRect<sup>10+</sup>            | [Rectangle](arkui-ts/ts-methods-alert-dialog-box.md#rectangle8) | No  | Mask area of the dialog box. Events outside the mask area are transparently transmitted, and events within the mask area are not.<br>Default value: **{ x: 0, y: 0, width: '100%', height: '100%' }**<br>**NOTE**<br>**maskRect** does not take effect when **showInSubWindow** is set to **true**.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
820| showInSubWindow<sup>11+</sup>     | boolean                                                      | No  | Whether to show the dialog box in a subwindow when it is not in the main window.<br>Default value: **false**, meaning the dialog box is displayed within the application, not in a separate subwindow<br>**NOTE**<br>A dialog box whose **showInSubWindow** attribute is **true** cannot trigger the display of another dialog box whose **showInSubWindow** attribute is also **true**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
821| isModal<sup>11+</sup>             | boolean                                                      | No  | Whether the dialog box is a modal. A modal dialog box has a mask applied, while a non-modal dialog box does not.<br>Default value: **true**<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
822| backgroundColor<sup>12+</sup>     | [ResourceColor](arkui-ts/ts-types.md#resourcecolor)          | No  | Background color of the dialog box.<br>Default value: **Color.Transparent**<br>**NOTE**<br>When **backgroundColor** is set to a non-transparent color, **backgroundBlurStyle** must be set to **BlurStyle.NONE**; otherwise, the color display may not meet the expected effect.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
823| backgroundBlurStyle<sup>12+</sup> | [BlurStyle](arkui-ts/ts-universal-attributes-background.md#blurstyle9) | No  | Background blur style of the dialog box.<br>Default value: **BlurStyle.COMPONENT_ULTRA_THICK**<br>**NOTE**<br>Setting this parameter to **BlurStyle.NONE** disables the background blur. When **backgroundBlurStyle** is set to a value other than **NONE**, do not set **backgroundColor**. If you do, the color display may not produce the expected visual effect.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
824| shadow<sup>12+</sup>              | [ShadowOptions](arkui-ts/ts-universal-attributes-image-effect.md#shadowoptions) \| [ShadowStyle](arkui-ts/ts-universal-attributes-image-effect.md#shadowstyle10) | No  | Shadow of the dialog box.<br> Default value on 2-in-1 devices: **ShadowStyle.OUTER_FLOATING_MD** when the dialog box is focused and **ShadowStyle.OUTER_FLOATING_SM** otherwise<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
825| enableHoverMode<sup>14+</sup>     | boolean                                                      | No  | Whether to enable the hover state.<br>Default value: **false**, meaning not to enable the hover state.<br>**Atomic service API**: This API can be used in atomic services since API version 14.           |
826| hoverModeArea<sup>14+</sup>       | [HoverModeAreaType](arkui-ts/ts-appendix-enums.md#hovermodeareatype14) | No  | Display area of the dialog box in the hover state.<br>Default value: **HoverModeAreaType.BOTTOM_SCREEN**<br>**Atomic service API**: This API can be used in atomic services since API version 14.|
827| levelMode<sup>15+</sup>       | [LevelMode](#levelmode15) | No  | Display level of the dialog box.<br>**NOTE**<br>- Default value: **LevelMode.OVERLAY**<br>- This parameter takes effect only when **showInSubWindow** is set to **false**.<br>**Atomic service API**: This API can be used in atomic services since API version 15.|
828| levelUniqueId<sup>15+</sup>       | number | No  | [Unique ID](js-apis-arkui-frameNode.md#getuniqueid12) of the node under the display level for the page-level dialog box.<br>**NOTE**<br>- This parameter takes effect only when **levelMode** is set to **LevelMode.EMBEDDED**.<br>**Atomic service API**: This API can be used in atomic services since API version 15.|
829| immersiveMode<sup>15+</sup>       | [ImmersiveMode](#immersivemode15) | No  | Overlay effect for the page-level dialog box.<br>**NOTE**<br>- Default value: **ImmersiveMode.DEFAULT**<br>- This parameter takes effect only when **levelMode** is set to **LevelMode.EMBEDDED**.<br>**Atomic service API**: This API can be used in atomic services since API version 15.|
830| levelOrder<sup>18+</sup>       | [LevelOrder](#levelorder18) | No  | Display order of the dialog box.<br>**NOTE**<br>- Default value: **LevelOrder.clamp(0)**<br>- Dynamic updating is not supported.<br>**Atomic service API**: This API can be used in atomic services since API version 18.|
831
832## ShowDialogSuccessResponse
833
834Describes the dialog box response result.
835
836**Atomic service API**: This API can be used in atomic services since API version 11.
837
838**System capability**: SystemCapability.ArkUI.ArkUI.Full
839
840| Name | Type  | Mandatory| Description                           |
841| ----- | ------ | ---- | ------------------------------- |
842| index | number | Yes  | Index of the selected button in the **buttons** array.|
843
844## ActionMenuOptions
845
846Describes the options for showing the action menu.
847
848**System capability**: SystemCapability.ArkUI.ArkUI.Full
849
850| Name                         | Type                                                        | Mandatory| Description                                                        |
851| ----------------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
852| title                         | string \| [Resource](arkui-ts/ts-types.md#resource) | No  | Title of the dialog box.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
853| buttons                       | [[Button](#button),[Button](#button)?,[Button](#button)?,[Button](#button)?,[Button](#button)?,[Button](#button)?] | Yes  | Array of menu item buttons. The array structure is **{text:'button', color: '\#666666'}**. Up to six buttons are supported. If there are more than six buttons, only the first six buttons will be displayed.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
854| showInSubWindow<sup>11+</sup> | boolean                                                      | No  | Whether to show the dialog box in a subwindow when it is not in the main window.<br>Default value: **false**, indicating that the dialog box is not displayed in the subwindow<br>**NOTE**<br> - A dialog box whose **showInSubWindow** attribute is **true** cannot trigger the display of another dialog box whose **showInSubWindow** attribute is also **true**.<br> - If **showInSubWindow** is set to **true** in **UIExtension**, the dialog box is aligned with the host window based on **UIExtension**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
855| isModal<sup>11+</sup>         | boolean                                                      | No  | Whether the dialog box is a modal. A modal dialog box has a mask applied, while a non-modal dialog box does not.<br>Default value: **true**<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
856| levelMode<sup>15+</sup>       | [LevelMode](#levelmode15) | No  | Display level of the dialog box.<br>**NOTE**<br>- Default value: **LevelMode.OVERLAY**<br>- This parameter takes effect only when **showInSubWindow** is set to **false**.<br>**Atomic service API**: This API can be used in atomic services since API version 15.|
857| levelUniqueId<sup>15+</sup>       | number | No  | [Unique ID](js-apis-arkui-frameNode.md#getuniqueid12) of the node under the display level for the page-level dialog box.<br>**NOTE**<br>- This parameter takes effect only when **levelMode** is set to **LevelMode.EMBEDDED**.<br>**Atomic service API**: This API can be used in atomic services since API version 15.|
858| immersiveMode<sup>15+</sup>       | [ImmersiveMode](#immersivemode15) | No  | Overlay effect for the page-level dialog box.<br>**NOTE**<br>- Default value: **ImmersiveMode.DEFAULT**<br>- This parameter takes effect only when **levelMode** is set to **LevelMode.EMBEDDED**.<br>**Atomic service API**: This API can be used in atomic services since API version 15.|
859
860## ActionMenuSuccessResponse
861
862Describes the action menu response result.
863
864**Atomic service API**: This API can be used in atomic services since API version 11.
865
866**System capability**: SystemCapability.ArkUI.ArkUI.Full
867
868| Name | Type  | Mandatory| Description                                    |
869| ----- | ------ | ---- | ---------------------------------------- |
870| index | number | Yes  | Index of the selected button in the **buttons** array, starting from **0**.|
871
872## DialogController<sup>18+</sup>
873
874Implements a custom dialog box controller that inherits from [CommonController](#commoncontroller18).
875
876It can be used as a member variable of **UIContext** to display custom dialog boxes. For specific usage, see the examples for [openCustomDialogWithController](js-apis-arkui-UIContext.md#opencustomdialogwithcontroller18) and [presentCustomDialog](js-apis-arkui-UIContext.md#presentcustomdialog18).
877
878**Atomic service API**: This API can be used in atomic services since API version 18.
879
880**System capability**: SystemCapability.ArkUI.ArkUI.Full
881
882## CommonController<sup>18+</sup>
883
884Implements a common controller for managing components related to **promptAction**.
885
886**Atomic service API**: This API can be used in atomic services since API version 18.
887
888**System capability**: SystemCapability.ArkUI.ArkUI.Full
889
890### constructor
891constructor()
892
893**Atomic service API**: This API can be used in atomic services since API version 18.
894
895**System capability**: SystemCapability.ArkUI.ArkUI.Full
896
897### close
898close(): void
899
900Closes the custom dialog box. If the dialog box is already closed, this API has no effect.
901
902**Atomic service API**: This API can be used in atomic services since API version 18.
903
904**System capability**: SystemCapability.ArkUI.ArkUI.Full
905
906## LevelOrder<sup>18+</sup>
907
908Defines the display order of a dialog box.
909
910**Atomic service API**: This API can be used in atomic services since API version 18.
911
912**System capability**: SystemCapability.ArkUI.ArkUI.Full
913
914### clamp<sup>18+</sup>
915static clamp(order: number): LevelOrder
916
917Creates a dialog box level with the specified order.
918
919**Atomic service API**: This API can be used in atomic services since API version 18.
920
921**System capability**: SystemCapability.ArkUI.ArkUI.Full
922
923**Parameters**
924
925| Name| Type   | Mandatory| Description                                                        |
926| ------ | ------- | ---- | ------------------------------------------------------------ |
927| order | number | Yes  | Display order of the dialog box. The value range is [-100000.0, +100000.0]. Values outside this range are clamped to the nearest limit.|
928
929**Return value**
930
931| Type | Description   |
932| ------ | ------ |
933| [LevelOrder](#levelorder18) | Current instance.|
934
935### getOrder<sup>18+</sup>
936getOrder(): number
937
938Obtains the display order of this dialog box.
939
940**Atomic service API**: This API can be used in atomic services since API version 18.
941
942**System capability**: SystemCapability.ArkUI.ArkUI.Full
943
944**Return value**
945
946| Type | Description   |
947| ------ | ------ |
948| number | Display order of the dialog box.|
949
950## DialogOptions<sup>18+</sup>
951
952Defines the options of the custom dialog box. This API extends [BaseDialogOptions](#basedialogoptions11).
953
954**Atomic service API**: This API can be used in atomic services since API version 18.
955
956**System capability**: SystemCapability.ArkUI.ArkUI.Full
957
958| Name   | Type                                                   | Mandatory| Description                                                        |
959| ------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
960| backgroundColor | [ResourceColor](arkui-ts/ts-types.md#resourcecolor)  | No| Background color of the dialog box.<br>Default value: **Color.Transparent**<br>**NOTE**<br>When **backgroundColor** is set to a non-transparent color, **backgroundBlurStyle** must be set to **BlurStyle.NONE**; otherwise, the color display may not meet the expected effect.|
961| cornerRadius | [DialogOptionsCornerRadius](#dialogoptionscornerradius18) | No| Background corner radius of the dialog box.<br>You can set separate radiuses for the four rounded corners.<br>Default value: **{ topLeft: '32vp', topRight: '32vp', bottomLeft: '32vp', bottomRight: '32vp' }**<br> The radius of the rounded corners is subject to the component size. Its maximum value is half of the component width or height. If the value is negative, the default value is used.<br> When set to a percentage, the value defines the radius as a percentage of the parent component's width or height.|
962| borderWidth | [DialogOptionsBorderWidth](#dialogoptionsborderwidth18) | No| Border width of the dialog box.<br>You can set the width for all four sides or set separate widths for individual sides.<br>Default value: **0**<br> When set to a percentage, the value defines the border width as a percentage of the parent dialog box's width.<br>If the left and right borders are greater than its width, or the top and bottom borders are greater than its height, the dialog box may not display as expected.|
963| borderColor | [DialogOptionsBorderColor](#dialogoptionsbordercolor18) | No| Border color of the dialog box.<br>Default value: **Color.Black**<br> **borderColor** must be used with **borderWidth** in pairs.|
964| borderStyle | [DialogOptionsBorderStyle](#dialogoptionsborderstyle18) | No| Border style of the dialog box.<br>Default value: **BorderStyle.Solid**<br> **borderStyle** must be used with **borderWidth** in pairs.|
965| width | [Dimension](arkui-ts/ts-types.md#dimension10) | No  | Width of the dialog box.<br>**NOTE**<br>- Default maximum width of the dialog box: 400 vp<br>- When this parameter is set to a percentage, the reference width of the dialog box is the width of the window where the dialog box is located. You can decrease or increase the width as needed.|
966| height | [Dimension](arkui-ts/ts-types.md#dimension10)  | No  | Height of the dialog box.<br>**NOTE**<br>- Default maximum height of the dialog box: 0.9 x (Window height – Safe area)<br>- When this parameter is set to a percentage, the reference height of the dialog box is the height of the window where the dialog box is located minus the safe area. You can decrease or increase the height as needed.|
967| shadow | [DialogOptionsShadow](#dialogoptionsshadow18) | No| Shadow of the dialog box.<br>Default value on 2-in-1 devices: **ShadowStyle.OUTER_FLOATING_MD** when the dialog box is focused and **ShadowStyle.OUTER_FLOATING_SM** otherwise|
968| backgroundBlurStyle | [BlurStyle](arkui-ts/ts-universal-attributes-background.md#blurstyle9)                 | No  | Background blur style of the dialog box.<br>Default value: **BlurStyle.COMPONENT_ULTRA_THICK**<br>**NOTE**<br>Setting this parameter to **BlurStyle.NONE** disables the background blur. When **backgroundBlurStyle** is set to a value other than **NONE**, do not set **backgroundColor**. If you do, the color display may not produce the expected visual effect.|
969
970## DialogOptionsCornerRadius<sup>18+</sup>
971
972type DialogOptionsCornerRadius = Dimension \| BorderRadiuses
973
974Defines the allowed data types for specifying the background corner radius of a dialog box.
975
976**Atomic service API**: This API can be used in atomic services since API version 18.
977
978**System capability**: SystemCapability.ArkUI.ArkUI.Full
979
980| Type                                                        | Description                        |
981| ------------------------------------------------------------ | ---------------------------- |
982| [Dimension](arkui-ts/ts-types.md#dimension10) | Length type used to represent a size unit.|
983| [BorderRadiuses](arkui-ts/ts-types.md#borderradiuses9) | Type used to describe the corner radius of a component's border.|
984
985## DialogOptionsBorderWidth<sup>18+</sup>
986
987type DialogOptionsBorderWidth = Dimension \| EdgeWidths
988
989Defines the allowed data types for specifying the background border width of a dialog box.
990
991**Atomic service API**: This API can be used in atomic services since API version 18.
992
993**System capability**: SystemCapability.ArkUI.ArkUI.Full
994
995| Type                                                        | Description                        |
996| ------------------------------------------------------------ | ---------------------------- |
997| [Dimension](arkui-ts/ts-types.md#dimension10) | Length type used to represent a size unit.|
998| [EdgeWidths](arkui-ts/ts-types.md#edgewidths9) | Type used to describe the edge width of a component in different directions.|
999
1000## DialogOptionsBorderColor<sup>18+</sup>
1001
1002type DialogOptionsBorderColor = ResourceColor \| EdgeColors
1003
1004Defines the allowed data types for specifying the background border color of a dialog box.
1005
1006**Atomic service API**: This API can be used in atomic services since API version 18.
1007
1008**System capability**: SystemCapability.ArkUI.ArkUI.Full
1009
1010| Type                                                        | Description                        |
1011| ------------------------------------------------------------ | ---------------------------- |
1012| [ResourceColor](arkui-ts/ts-types.md#resourcecolor) | Color type used to describe resource colors.|
1013| [EdgeColors](arkui-ts/ts-types.md#edgecolors9) | Type used to describe the border color for each edge of a component.|
1014
1015## DialogOptionsBorderStyle<sup>18+</sup>
1016
1017type DialogOptionsBorderStyle = BorderStyle \| EdgeStyles
1018
1019Defines the allowed data types for specifying the background border style of a dialog box.
1020
1021**Atomic service API**: This API can be used in atomic services since API version 18.
1022
1023**System capability**: SystemCapability.ArkUI.ArkUI.Full
1024
1025| Type                                                        | Description                        |
1026| ------------------------------------------------------------ | ---------------------------- |
1027| [BorderStyle](arkui-ts/ts-appendix-enums.md#borderstyle) | Type used to describe the border style of a component.|
1028| [EdgeStyles](arkui-ts/ts-types.md#edgestyles9) | Type used to describe the border style for each edge of a component.|
1029
1030## DialogOptionsShadow<sup>18+</sup>
1031
1032type DialogOptionsShadow = ShadowOptions \| ShadowStyle
1033
1034Defines the allowed data types for specifying the background shadow of a dialog box.
1035
1036**Atomic service API**: This API can be used in atomic services since API version 18.
1037
1038**System capability**: SystemCapability.ArkUI.ArkUI.Full
1039
1040| Type                                                        | Description                        |
1041| ------------------------------------------------------------ | ---------------------------- |
1042| [ShadowOptions](arkui-ts/ts-universal-attributes-image-effect.md#shadowoptions) | Type used to describe shadow attributes, including the blur radius, color, and offset along the x-axis and y-axis.|
1043| [ShadowStyle](arkui-ts/ts-universal-attributes-image-effect.md#shadowstyle10) | Type used to describe the shadow style.|
1044
1045## CustomDialogOptions<sup>11+</sup>
1046
1047Defines the options of a custom dialog box, which inherit from [BaseDialogOptions](#basedialogoptions11).
1048
1049**Atomic service API**: This API can be used in atomic services since API version 12.
1050
1051**System capability**: SystemCapability.ArkUI.ArkUI.Full
1052
1053| Name   | Type                                                   | Mandatory| Description                                                        |
1054| ------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
1055| builder | [CustomBuilder](arkui-ts/ts-types.md#custombuilder8) | Yes | Content of the custom dialog box.<br>**NOTE**<br>The builder needs to be assigned an arrow function in the following format: () => { this.XXX() }, where XXX indicates the internal builder name.<br>If you are working with a global builder, you need to call it within a local builder within a component.<br>The aspect ratio of the root node of a builder is relative to the size of the dialog box container.<br>The aspect ratio of a non-root node is relative to the size of its parent node.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
1056| backgroundColor <sup>12+</sup>| [ResourceColor](arkui-ts/ts-types.md#resourcecolor)  | No| Background color of the dialog box.<br>Default value: **Color.Transparent**<br>**NOTE**<br>When **backgroundColor** is set to a non-transparent color, **backgroundBlurStyle** must be set to **BlurStyle.NONE**; otherwise, the color display may not meet the expected effect.|
1057| cornerRadius<sup>12+</sup>| [Dimension](arkui-ts/ts-types.md#dimension10) \| [BorderRadiuses](arkui-ts/ts-types.md#borderradiuses9) | No| Radius of the rounded corners of the background.<br>You can set separate radiuses for the four rounded corners.<br>Default value: **{ topLeft: '32vp', topRight: '32vp', bottomLeft: '32vp', bottomRight: '32vp' }**<br> The radius of the rounded corners is subject to the component size. Its maximum value is half of the component width or height. If the value is negative, the default value is used.<br> When set to a percentage, the value defines the radius as a percentage of the parent component's width or height.|
1058| borderWidth<sup>12+</sup>| [Dimension](arkui-ts/ts-types.md#dimension10) \| [EdgeWidths](arkui-ts/ts-types.md#edgewidths9)  | No| Border width of the dialog box.<br>You can set the width for all four sides or set separate widths for individual sides.<br>Default value: **0**<br> When set to a percentage, the value defines the border width as a percentage of the parent dialog box's width.<br>If the left and right borders are greater than its width, or the top and bottom borders are greater than its height, the dialog box may not display as expected.|
1059| borderColor<sup>12+</sup> | [ResourceColor](arkui-ts/ts-types.md#resourcecolor) \| [EdgeColors](arkui-ts/ts-types.md#edgecolors9)  | No| Border color of the dialog box.<br>Default value: **Color.Black**<br> **borderColor** must be used with **borderWidth** in pairs.|
1060| borderStyle<sup>12+</sup> | [BorderStyle](arkui-ts/ts-appendix-enums.md#borderstyle) \| [EdgeStyles](arkui-ts/ts-types.md#edgestyles9)  | No| Border style of the dialog box.<br>Default value: **BorderStyle.Solid**<br> **borderStyle** must be used with **borderWidth** in pairs.|
1061| width<sup>12+</sup> | [Dimension](arkui-ts/ts-types.md#dimension10) | No  | Width of the dialog box.<br>**NOTE**<br>- Default maximum width of the dialog box: 400 vp<br>- When this parameter is set to a percentage, the reference width of the dialog box is the width of the window where the dialog box is located. You can decrease or increase the width as needed.|
1062| height<sup>12+</sup> | [Dimension](arkui-ts/ts-types.md#dimension10)  | No  | Height of the dialog box.<br>**NOTE**<br>- Default maximum height of the dialog box: 0.9 x (Window height – Safe area)<br>- When this parameter is set to a percentage, the reference height of the dialog box is the height of the window where the dialog box is located minus the safe area. You can decrease or increase the height as needed.|
1063| shadow<sup>12+</sup>| [ShadowOptions](arkui-ts/ts-universal-attributes-image-effect.md#shadowoptions) \| [ShadowStyle](arkui-ts/ts-universal-attributes-image-effect.md#shadowstyle10)   | No| Shadow of the dialog box.<br>Default value on 2-in-1 devices: **ShadowStyle.OUTER_FLOATING_MD** when the dialog box is focused and **ShadowStyle.OUTER_FLOATING_SM** otherwise|
1064| backgroundBlurStyle<sup>12+</sup> | [BlurStyle](arkui-ts/ts-universal-attributes-background.md#blurstyle9)                 | No  | Background blur style of the dialog box.<br>Default value: **BlurStyle.COMPONENT_ULTRA_THICK**<br>**NOTE**<br>Setting this parameter to **BlurStyle.NONE** disables the background blur. When **backgroundBlurStyle** is set to a value other than **NONE**, do not set **backgroundColor**. If you do, the color display may not produce the expected visual effect.|
1065
1066## BaseDialogOptions<sup>11+</sup>
1067
1068Defines the options of the dialog box.
1069
1070**System capability**: SystemCapability.ArkUI.ArkUI.Full
1071
1072| Name           | Type                                                        | Mandatory| Description                                                        |
1073| --------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1074| maskRect        | [Rectangle](arkui-ts/ts-methods-alert-dialog-box.md#rectangle8) | No  | Mask area.<br>Default value: **{ x: 0, y: 0, width: '100%', height: '100%' }**<br>**NOTE**<br>**maskRect** does not take effect when **showInSubWindow** is set to **true**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
1075| alignment       | [DialogAlignment](arkui-ts/ts-methods-alert-dialog-box.md#dialogalignment) | No  | Alignment mode of the dialog box in the vertical direction.<br>Default value: **DialogAlignment.Default**<br>**NOTE**<br>If **showInSubWindow** is set to **true** in **UIExtension**, the dialog box is aligned with the host window based on **UIExtension**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
1076| offset          | [Offset](arkui-ts/ts-types.md#offset)                     | No  | Offset of the dialog box based on the **alignment** settings.<br>Default value: **{ dx: 0 , dy: 0 }**<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
1077| isModal         | boolean                                                      | No  | Whether the dialog box is a modal. A modal dialog box has a mask applied, while a non-modal dialog box does not.<br>Default value: **true**<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
1078| showInSubWindow | boolean                                                      | No  | Whether to show the dialog box in a subwindow when it is not in the main window.<br>Default value: **false**, meaning the dialog box is displayed within the application, not in a separate subwindow<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
1079| onWillDismiss<sup>12+</sup> | Callback<[DismissDialogAction](#dismissdialogaction12)> | No| Callback for interactive dismissal of the dialog box.<br>**NOTE**<br>1. If this callback is registered, the dialog box will not be dismissed immediately after the user touches the mask or the Back button, presses the Esc key, or swipes left or right on the screen. The **reason** parameter in the callback is used to determine whether the dialog box can be dismissed. The reason returned by the component does not support the value **CLOSE_BUTTON**.<br>2. In the **onWillDismiss** callback, another **onWillDismiss** callback is not allowed.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
1080|  autoCancel<sup>12+</sup> |       boolean                                   | No  | Whether to dismiss the dialog box when the mask is touched. The value **true** means to dismiss the dialog box when the mask is touched, and **false** means the opposite.<br>Default value: **true**<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
1081|  maskColor<sup>12+</sup> |        [ResourceColor](arkui-ts/ts-types.md#resourcecolor) | No   | Mask color.<br>Default value: **0x33000000**<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
1082| transition<sup>12+</sup>          | [TransitionEffect](arkui-ts/ts-transition-animation-component.md#transitioneffect10) | No  | Transition effect for the entrance and exit of the dialog box.<br>**NOTE**<br> 1. If this parameter is not set, the default effect is used.<br> 2. Touching the Back button during the entrance animation pauses the entrance animation and starts the exit animation. The final effect is one obtained after the curves of the entrance and exit animations are combined.<br> 3. Touching the Back button during the exit animation does not affect the animation playback. Touching the Back button again closes the application.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
1083| onDidAppear<sup>12+</sup> | () => void | No| Event callback when the dialog box appears.<br>**NOTE**<br>1. The normal timing sequence is as follows: onWillAppear > onDidAppear > (onDateAccept/onCancel/onDateChange) > onWillDisappear > onDidDisappear.<br>2. You can set the callback event for changing the dialog box display effect in **onDidAppear**. The settings take effect next time the dialog box appears.<br>3. If the user dismisses the dialog box immediately after it appears, **onWillDisappear** is invoked before **onDidAppear**.<br>4. If the dialog box is dismissed before its entrance animation is finished, this callback is not invoked.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
1084| onDidDisappear<sup>12+</sup> | () => void | No| Event callback when the dialog box disappears.<br>**NOTE**<br>The normal timing sequence is as follows: onWillAppear > onDidAppear > (onDateAccept/onCancel/onDateChange) > onWillDisappear > onDidDisappear.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
1085| onWillAppear<sup>12+</sup> | () => void | No| Event callback when the dialog box is about to appear.<br>**NOTE**<br>1. The normal timing sequence is as follows: onWillAppear > onDidAppear > (onDateAccept/onCancel/onDateChange) > onWillDisappear > onDidDisappear.<br>2. You can set the callback event for changing the dialog box display effect in **onWillAppear**. The settings take effect next time the dialog box appears.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
1086| onWillDisappear<sup>12+</sup> | () => void | No| Event callback when the dialog box is about to disappear.<br>**NOTE**<br>1. The normal timing sequence is as follows: onWillAppear > onDidAppear > (onDateAccept/onCancel/onDateChange) > onWillDisappear > onDidDisappear.<br>2. If the user dismisses the dialog box immediately after it appears, **onWillDisappear** is invoked before **onDidAppear**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
1087| keyboardAvoidMode<sup>12+</sup> | [KeyboardAvoidMode](./arkui-ts/ts-types.md#keyboardavoidmode12) | No| How the dialog box avoids the soft keyboard when it is brought up.<br>Default value: **KeyboardAvoidMode.DEFAULT**<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
1088| enableHoverMode<sup>14+</sup>   | boolean | No  | Whether to enable the hover state.<br>Default value: **false**, meaning not to enable the hover state.<br>**Atomic service API**: This API can be used in atomic services since API version 14.|
1089| hoverModeArea<sup>14+</sup>     | [HoverModeAreaType](arkui-ts/ts-appendix-enums.md#hovermodeareatype14) | No  | Display area of the dialog box in the hover state.<br>Default value: **HoverModeAreaType.BOTTOM_SCREEN**<br>**Atomic service API**: This API can be used in atomic services since API version 14.|
1090| keyboardAvoidDistance<sup>15+</sup>       | [LengthMetrics](js-apis-arkui-graphics.md#lengthmetrics12) | No  | Distance between the dialog box and the keyboard after keyboard avoidance is applied.<br>**NOTE**<br>- Default value: **16vp**<br>- Default unit: vp<br>- This parameter takes effect only when **keyboardAvoidMode** is set to **DEFAULT**.<br>**Atomic service API**: This API can be used in atomic services since API version 15.|
1091| levelMode<sup>15+</sup>       | [LevelMode](#levelmode15) | No  | Display level of the dialog box.<br>**NOTE**<br>- Default value: **LevelMode.OVERLAY**<br>- This parameter takes effect only when **showInSubWindow** is set to **false**.<br>**Atomic service API**: This API can be used in atomic services since API version 15.|
1092| levelUniqueId<sup>15+</sup>       | number | No  | [Unique ID](js-apis-arkui-frameNode.md#getuniqueid12) of the node under the display level for the page-level dialog box.<br>**NOTE**<br>- This parameter takes effect only when **levelMode** is set to **LevelMode.EMBEDDED**.<br>**Atomic service API**: This API can be used in atomic services since API version 15.|
1093| immersiveMode<sup>15+</sup>       | [ImmersiveMode](#immersivemode15) | No  | Overlay effect for the page-level dialog box.<br>**NOTE**<br>- Default value: **ImmersiveMode.DEFAULT**<br>- This parameter takes effect only when **levelMode** is set to **LevelMode.EMBEDDED**.<br>**Atomic service API**: This API can be used in atomic services since API version 15.|
1094| levelOrder<sup>18+</sup>       | [LevelOrder](#levelorder18) | No  | Display order of the dialog box.<br>**NOTE**<br>- Default value: **LevelOrder.clamp(0)**<br>- Dynamic updating is not supported.<br>**Atomic service API**: This API can be used in atomic services since API version 18.|
1095
1096## DismissDialogAction<sup>12+</sup>
1097
1098Provides information about the action to dismiss the dialog box.
1099
1100**Atomic service API**: This API can be used in atomic services since API version 12.
1101
1102**System capability**: SystemCapability.ArkUI.ArkUI.Full
1103
1104### Attributes
1105
1106| Name   | Type                                                        | Readable| Writable| Description                                                        |
1107| ------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ |
1108| dismiss | Callback&lt;void&gt;                                         | No  | No  | Callback for dismissing the dialog box. This API is called only when the dialog box needs to be exited.|
1109| reason  | [DismissReason](#dismissreason12) | No  | No  | Reason why the dialog box cannot be dismissed. You must specify whether to dismiss the dialog box for each of the listed actions.|
1110
1111## DismissReason<sup>12+</sup>
1112
1113**Atomic service API**: This API can be used in atomic services since API version 12.
1114
1115**System capability**: SystemCapability.ArkUI.ArkUI.Full
1116
1117| Name         | Value  | Description                                                        |
1118| ------------- | ---- | ------------------------------------------------------------ |
1119| PRESS_BACK    | 0    | Touching the Back button, swiping left or right on the screen, or pressing the Esc key.                          |
1120| TOUCH_OUTSIDE | 1    | Touching the mask.                                              |
1121| CLOSE_BUTTON  | 2    | Touching the Close button.                                              |
1122| SLIDE_DOWN    | 3    | Sliding down.<br>**NOTE**<br>This API is effective only in [sheet transition](./arkui-ts/ts-universal-attributes-sheet-transition.md).|
1123
1124## LevelMode<sup>15+</sup>
1125
1126Enumerates the display level modes of the dialog box.
1127
1128**Atomic service API**: This API can be used in atomic services since API version 15.
1129
1130**System capability**: SystemCapability.ArkUI.ArkUI.Full
1131
1132| Name   | Value  | Description                                            |
1133| ------- | ---- | ------------------------------------------------ |
1134| OVERLAY | 0    | The dialog box is displayed at the root node level of the application window and remain visible during navigation.|
1135| EMBEDDED    | 1    | The dialog box is a child of the page's route/navigation and is hidden when the page is hidden.|
1136
1137## ImmersiveMode<sup>15+</sup>
1138
1139Enumerates the display area modes of the dialog box overlay within a page.
1140
1141**Atomic service API**: This API can be used in atomic services since API version 15.
1142
1143**System capability**: SystemCapability.ArkUI.ArkUI.Full
1144
1145| Name   | Value  | Description                                            |
1146| ------- | ---- | ------------------------------------------------ |
1147| DEFAULT | 0    | The dialog box overlay follows the layout constraints of its parent node.|
1148| EXTEND    | 1    | The dialog box overlay can extend to cover the status bar and navigation bar for a more immersive look.
1149
1150## Button
1151
1152Describes the menu item button in the action menu.
1153
1154**System capability**: SystemCapability.ArkUI.ArkUI.Full
1155
1156| Name   | Type                                      | Mandatory  | Description     |
1157| ----- | ---------------------------------------- | ---- | ------- |
1158| text  | string \| [Resource](arkui-ts/ts-types.md#resource)| Yes   | Button text.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
1159| color | string \|  [Resource](arkui-ts/ts-types.md#resource) | Yes   | Text color of the button.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
1160| primary<sup>12+</sup> | boolean | No   | Whether the button responds to the **Enter** key by default when the dialog box has focus and the **Tab** key is not pressed for sequential focus navigation. If there are multiple buttons, set this parameter to **true** for only one button. Otherwise, no button will respond. Multiple dialog boxes can automatically gain focus and respond to user interactions in a sequential manner.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
1161