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).
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 parameter 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>12+</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 12.
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 parameter 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@Entry
119@Component
120struct toastExample {
121  @State toastId: number = 0;
122  build() {
123    Column() {
124      Button('Open Toast')
125        .height(100)
126        .onClick(() => {
127          try {
128            promptAction.openToast({
129              message: 'Toast Massage',
130              duration: 10000,
131            }).then((toastId: number) => {
132              this.toastId = toastId;
133            });
134          } catch (error) {
135            let message = (error as BusinessError).message;
136            let code = (error as BusinessError).code;
137            console.error(`OpenToast error code is ${code}, message is ${message}`);
138          };
139        })
140      Blank().height(50);
141      Button('Close Toast')
142        .height(100)
143        .onClick(() => {
144          try {
145            promptAction.closeToast(this.toastId);
146          } catch (error) {
147            let message = (error as BusinessError).message;
148            let code = (error as BusinessError).code;
149            console.error(`CloseToast error code is ${code}, message is ${message}`);
150          };
151        })
152    }.height('100%').width('100%').justifyContent(FlexAlign.Center)
153  }
154}
155```
156
157![toast-openclose](figures/toast-openclose.gif)
158
159## promptAction.closeToast<sup>12+</sup>
160
161closeToast(toastId: number): void
162
163Closes a toast.
164
165**Atomic service API**: This API can be used in atomic services since API version 12.
166
167**System capability**: SystemCapability.ArkUI.ArkUI.Full
168
169**Parameters**
170
171| Name | Type  | Mandatory | Description                         |
172| ------- | ------ | ---- | ----------------------------- |
173| toastId | number | Yes  | ID of the toast to close, which is returned by **openToast**. |
174
175**Error codes**
176
177For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
178
179| ID | Error Message                                                    |
180| -------- | ------------------------------------------------------------ |
181| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. |
182| 100001   | Internal error.                                              |
183
184**Example**
185
186See the example of [promptAction.openToaset12](#promptactionopentoast12).
187## promptAction.showDialog
188
189showDialog(options: ShowDialogOptions): Promise&lt;ShowDialogSuccessResponse&gt;
190
191Shows a dialog box. This API uses a promise to return the result asynchronously.
192
193**Atomic service API**: This API can be used in atomic services since API version 11.
194
195**System capability**: SystemCapability.ArkUI.ArkUI.Full
196
197**Parameters**
198
199| Name    | Type                                     | Mandatory  | Description    |
200| ------- | --------------------------------------- | ---- | ------ |
201| options | [ShowDialogOptions](#showdialogoptions) | Yes   | Dialog box options. |
202
203**Return value**
204
205| Type                                      | Description      |
206| ---------------------------------------- | -------- |
207| Promise&lt;[ShowDialogSuccessResponse](#showdialogsuccessresponse)&gt; | Promise used to return the dialog box response result. |
208
209**Error codes**
210
211For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
212
213| ID  | Error Message |
214| --------- | ------- |
215| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
216| 100001    | Internal error. |
217
218**Example**
219
220```ts
221import { promptAction } from '@kit.ArkUI'
222import { BusinessError } from '@kit.BasicServicesKit';
223
224try {
225  promptAction.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} catch (error) {
246  let message = (error as BusinessError).message
247  let code = (error as BusinessError).code
248  console.error(`showDialog args error code is ${code}, message is ${message}`);
249};
250```
251
252![en-us_image_0002](figures/en-us_image_0002.gif)
253
254## promptAction.showDialog
255
256showDialog(options: ShowDialogOptions, callback: AsyncCallback&lt;ShowDialogSuccessResponse&gt;):void
257
258Shows a dialog box. This API uses an asynchronous callback to return the result.
259
260**Atomic service API**: This API can be used in atomic services since API version 11.
261
262**System capability**: SystemCapability.ArkUI.ArkUI.Full
263
264**Parameters**
265
266| Name     | Type                                      | Mandatory  | Description          |
267| -------- | ---------------------------------------- | ---- | ------------ |
268| options  | [ShowDialogOptions](#showdialogoptions)  | Yes   | Dialog box options. |
269| callback | AsyncCallback&lt;[ShowDialogSuccessResponse](#showdialogsuccessresponse)&gt; | Yes   | Callback used to return the dialog box response result.  |
270
271**Error codes**
272
273For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
274
275| ID  | Error Message |
276| --------- | ------- |
277| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
278| 100001    | Internal error. |
279
280**Example**
281
282```ts
283import { promptAction } from '@kit.ArkUI';
284import { BusinessError } from '@kit.BasicServicesKit';
285
286try {
287  promptAction.showDialog({
288    title: 'showDialog Title Info',
289    message: 'Message Info',
290    buttons: [
291      {
292        text: 'button1',
293        color: '#000000'
294      },
295      {
296        text: 'button2',
297        color: '#000000'
298      }
299    ]
300  }, (err, data) => {
301    if (err) {
302      console.info('showDialog err: ' + err);
303      return;
304    }
305    console.info('showDialog success callback, click button: ' + data.index);
306  });
307} catch (error) {
308  let message = (error as BusinessError).message
309  let code = (error as BusinessError).code
310  console.error(`showDialog args error code is ${code}, message is ${message}`);
311};
312```
313
314![en-us_image_0002](figures/en-us_image_0002.gif)
315
316When the **showInSubWindow** attribute is set to **true**, the toast can be displayed outside the window.
317
318```ts
319import { promptAction } from '@kit.ArkUI';
320import { BusinessError } from '@kit.BasicServicesKit';
321
322try {
323  promptAction.showDialog({
324    title: 'showDialog Title Info',
325    message: 'Message Info',
326    isModal: true,
327    showInSubWindow: true,
328    buttons: [
329      {
330        text: 'button1',
331        color: '#000000'
332      },
333      {
334        text: 'button2',
335        color: '#000000'
336      }
337    ]
338  }, (err, data) => {
339    if (err) {
340      console.info('showDialog err: ' + err);
341      return;
342    }
343    console.info('showDialog success callback, click button: ' + data.index);
344  });
345} catch (error) {
346  let message = (error as BusinessError).message
347  let code = (error as BusinessError).code
348  console.error(`showDialog args error code is ${code}, message is ${message}`);
349};
350```
351
352![en-us_image_0002_showinsubwindow](figures/en-us_image_0002_showinsubwindow.jpg)
353
354
355
356## promptAction.showActionMenu
357
358showActionMenu(options: ActionMenuOptions, callback: AsyncCallback&lt;ActionMenuSuccessResponse&gt;):void
359
360Shows an action menu. This API uses a callback to return the result asynchronously.
361
362**Atomic service API**: This API can be used in atomic services since API version 11.
363
364**System capability**: SystemCapability.ArkUI.ArkUI.Full
365
366**Parameters**
367
368| Name     | Type                                      | Mandatory  | Description       |
369| -------- | ---------------------------------------- | ---- | --------- |
370| options  | [ActionMenuOptions](#actionmenuoptions)  | Yes   | Action menu options.  |
371| callback | AsyncCallback&lt;[ActionMenuSuccessResponse](#actionmenusuccessresponse)> | Yes   | Callback used to return the action menu response result. |
372
373**Error codes**
374
375For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
376
377| ID  | Error Message |
378| --------- | ------- |
379| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
380| 100001    | Internal error. |
381
382**Example**
383
384```ts
385import { promptAction } from '@kit.ArkUI';
386import { BusinessError } from '@kit.BasicServicesKit';
387
388try {
389  promptAction.showActionMenu({
390    title: 'Title Info',
391    buttons: [
392      {
393        text: 'item1',
394        color: '#666666'
395      },
396      {
397        text: 'item2',
398        color: '#000000'
399      },
400    ]
401  }, (err, data) => {
402    if (err) {
403      console.info('showActionMenu err: ' + err);
404      return;
405    }
406    console.info('showActionMenu success callback, click button: ' + data.index);
407  })
408} catch (error) {
409  let message = (error as BusinessError).message
410  let code = (error as BusinessError).code
411  console.error(`showActionMenu args error code is ${code}, message is ${message}`);
412};
413```
414
415![en-us_image_0005](figures/en-us_image_0005.gif)
416
417## promptAction.showActionMenu
418
419showActionMenu(options: ActionMenuOptions): Promise&lt;ActionMenuSuccessResponse&gt;
420
421Shows an action menu. This API uses a promise to return the result asynchronously.
422
423**Atomic service API**: This API can be used in atomic services since API version 11.
424
425**System capability**: SystemCapability.ArkUI.ArkUI.Full
426
427**Parameters**
428
429| Name    | Type                                     | Mandatory  | Description     |
430| ------- | --------------------------------------- | ---- | ------- |
431| options | [ActionMenuOptions](#actionmenuoptions) | Yes   | Action menu options. |
432
433**Return value**
434
435| Type                                      | Description     |
436| ---------------------------------------- | ------- |
437| Promise&lt;[ActionMenuSuccessResponse](#actionmenusuccessresponse)&gt; | Promise used to return the action menu response result. |
438
439**Error codes**
440
441For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
442
443| ID  | Error Message |
444| --------- | ------- |
445| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
446| 100001    | Internal error. |
447
448**Example**
449
450```ts
451import { promptAction } from '@kit.ArkUI';
452import { BusinessError } from '@kit.BasicServicesKit';
453
454try {
455  promptAction.showActionMenu({
456    title: 'showActionMenu Title Info',
457    buttons: [
458      {
459        text: 'item1',
460        color: '#666666'
461      },
462      {
463        text: 'item2',
464        color: '#000000'
465      },
466    ]
467  })
468    .then(data => {
469      console.info('showActionMenu success, click button: ' + data.index);
470    })
471    .catch((err:Error) => {
472      console.info('showActionMenu error: ' + err);
473    })
474} catch (error) {
475  let message = (error as BusinessError).message
476  let code = (error as BusinessError).code
477  console.error(`showActionMenu args error code is ${code}, message is ${message}`);
478};
479```
480
481![en-us_image_0005](figures/en-us_image_0005.gif)
482
483## promptAction.openCustomDialog<sup>11+</sup>
484
485openCustomDialog(options: CustomDialogOptions): Promise&lt;number&gt;
486
487Opens a custom dialog box.
488
489This API cannot be used in **ServiceExtension**.
490
491**isModal = true** and **showInSubWindow = true** cannot be used at the same time.
492
493By 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.
494
495**Atomic service API**: This API can be used in atomic services since API version 12.
496
497**System capability**: SystemCapability.ArkUI.ArkUI.Full
498
499**Parameters**
500
501| Name | Type                                         | Mandatory | Description              |
502| ------- | --------------------------------------------- | ---- | ------------------ |
503| options | [CustomDialogOptions](#customdialogoptions11) | Yes  | Content of the custom dialog box. |
504
505**Return value**
506
507| Type                 | Description                                 |
508| --------------------- | ------------------------------------- |
509| Promise&lt;number&gt; | ID of the custom dialog box, which can be used in **closeCustomDialog**. |
510
511**Error codes**
512
513For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
514
515| ID | Error Message                          |
516| -------- | ---------------------------------- |
517| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
518| 100001   | Internal error. |
519
520**Example**
521
522```ts
523import { promptAction } from '@kit.ArkUI'
524
525@Entry
526@Component
527struct Index {
528  private customDialogComponentId: number = 0
529
530  @Builder customDialogComponent() {
531    Column() {
532      Text('Toast').fontSize(30)
533      Row({ space: 50 }) {
534        Button ("OK").onClick () => {
535          promptAction.closeCustomDialog(this.customDialogComponentId)
536        })
537        Button ("Cancel").onClick () => {
538          promptAction.closeCustomDialog(this.customDialogComponentId)
539        })
540      }
541    }.height(200).padding(5).justifyContent(FlexAlign.SpaceBetween)
542  }
543
544  build() {
545    Row() {
546      Column({ space: 20 }) {
547        Text('In-component dialog box')
548          .fontSize(30)
549          .onClick(() => {
550            promptAction.openCustomDialog({
551              builder: () => {
552                this.customDialogComponent()
553              },
554              onWillDismiss: (dismissDialogAction: DismissDialogAction) => {
555                console.info("reason" + JSON.stringify(dismissDialogAction.reason))
556                console.log("dialog onWillDismiss")
557                if (dismissDialogAction.reason == DismissReason.PRESS_BACK) {
558                  dismissDialogAction.dismiss()
559                }
560                if (dismissDialogAction.reason == DismissReason.TOUCH_OUTSIDE) {
561                  dismissDialogAction.dismiss()
562                }
563              }
564            }).then((dialogId: number) => {
565              this.customDialogComponentId = dialogId
566            })
567          })
568      }
569      .width('100%')
570    }
571    .height('100%')
572  }
573}
574
575```
576This example demonstrates how to set styles of a dialog box, including the width, height, background color, and shadow.
577```ts
578import { promptAction } from '@kit.ArkUI'
579
580let customDialogId: number = 0
581
582@Builder
583function customDialogBuilder() {
584  Column() {
585    Text('Custom dialog Message').fontSize(10)
586    Row() {
587      Button ("OK").onClick () => {
588        promptAction.closeCustomDialog(customDialogId)
589      })
590      Blank().width(50)
591      Button ("Cancel").onClick () => {
592        promptAction.closeCustomDialog(customDialogId)
593      })
594    }
595  }
596}
597
598@Entry
599@Component
600struct Index {
601  @State message: string = 'Hello World'
602
603  @Builder
604  customDialogComponent() {
605    customDialogBuilder()
606  }
607
608  build() {
609    Row() {
610      Column() {
611        Text(this.message)
612          .fontSize(50)
613          .fontWeight(FontWeight.Bold)
614          .onClick(() => {
615            promptAction.openCustomDialog({
616              builder: () => {
617                this.customDialogComponent()
618              },
619              showInSubWindow: false,
620              offset: { dx: 5, dy: 5 },
621              backgroundColor: 0xd9ffffff,
622              cornerRadius: 20,
623              width: '80%',
624              height: 200,
625              borderWidth: 1,
626              borderStyle: BorderStyle.Dashed, // borderStyle must be used with borderWidth in pairs.
627              borderColor: Color.Blue, // borderColor must be used with borderWidth in pairs.
628              shadow: ({
629                radius: 20,
630                color: Color.Grey,
631                offsetX: 50,
632                offsetY: 0
633              }),
634            }).then((dialogId: number) => {
635              customDialogId = dialogId
636            })
637          })
638      }
639      .width('100%')
640    }
641    .height('100%')
642  }
643}
644```
645![en-us_image_0007](figures/en-us_image_0007.gif)
646
647## promptAction.closeCustomDialog<sup>11+</sup>
648
649closeCustomDialog(dialogId: number): void
650
651Closes the specified custom dialog box.
652
653**Atomic service API**: This API can be used in atomic services since API version 12.
654
655**System capability**: SystemCapability.ArkUI.ArkUI.Full
656
657**Parameters**
658
659| Name  | Type  | Mandatory | Description                            |
660| -------- | ------ | ---- | -------------------------------- |
661| dialogId | number | Yes  | ID of the custom dialog box to close. It is returned from **openCustomDialog**. |
662
663**Error codes**
664
665For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
666
667| ID | Error Message                          |
668| -------- | ---------------------------------- |
669| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
670| 100001   | Internal error. |
671
672**Example**
673
674See the example of [promptAction.openCustomDialog](#promptactionopencustomdialog11).
675
676## ShowToastOptions
677
678Describes the options for showing the toast.
679
680**System capability**: SystemCapability.ArkUI.ArkUI.Full
681
682| Name                   | Type                                                        | Mandatory | Description                                                        |
683| ----------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
684| 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. |
685| 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. |
686| bottom                  | string \| number                                   | No  | Distance between the toast border and the bottom of the screen.<br>Default value: **80vp**<br>This parameter does not take effect after **Alignment** is set.<br>**Atomic service API**: This API can be used in atomic services since API version 11. |
687| 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. |
688| 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.        |
689| 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>**Atomic service API**: This API can be used in atomic services since API version 12. |
690| 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. |
691| textColor<sup>12+</sup>    | [ResourceColor](arkui-ts/ts-types.md#resourcecolor) | No  | Font color of the toast.<br>Default value: **Color.Black** |
692| backgroundBlurStyle<sup>12+</sup>    | [BlurStyle](arkui-ts/ts-appendix-enums.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. |
693| 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.OuterDefaultMD** |
694
695## ToastShowMode<sup>11+</sup>
696
697Describes the mode in which the toast is shown.
698
699**Atomic service API**: This API can be used in atomic services since API version 12.
700
701**System capability**: SystemCapability.ArkUI.ArkUI.Full
702
703| Name    | Value  | Description                  |
704| -------- | ---- | ---------------------- |
705| DEFAULT  | 0    | The toast is shown within the application.  |
706| TOP_MOST | 1    | The toast is shown above the application. |
707
708## ShowDialogOptions
709
710Describes the options for showing the dialog box.
711
712**System capability**: SystemCapability.ArkUI.ArkUI.Full
713
714| Name                             | Type                                                        | Mandatory | Description                                                        |
715| --------------------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
716| 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. |
717| 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. |
718| 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. |
719| 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. |
720| 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. |
721| 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. |
722| showInSubWindow<sup>11+</sup>     | boolean                                                      | No  | Whether to show the dialog box in a sub-window.<br>Default value: **false**<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. |
723| 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. |
724| backgroundColor<sup>12+</sup>     | [ResourceColor](arkui-ts/ts-types.md#resourcecolor)          | No  | Background color of the dialog box.<br>Default value: **Color.Transparent**<br>**Atomic service API**: This API can be used in atomic services since API version 12.                |
725| backgroundBlurStyle<sup>12+</sup> | [BlurStyle](arkui-ts/ts-appendix-enums.md#blurstyle9)        | No  | Background blur style of the dialog box.<br>Default value: **BlurStyle.COMPONENT_ULTRA_THICK**<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
726| 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. |
727
728## ShowDialogSuccessResponse
729
730Describes the dialog box response result.
731
732**Atomic service API**: This API can be used in atomic services since API version 11.
733
734**System capability**: SystemCapability.ArkUI.ArkUI.Full
735
736| Name | Type  | Mandatory | Description                           |
737| ----- | ------ | ---- | ------------------------------- |
738| index | number | Yes  | Index of the selected button in the **buttons** array. |
739
740## ActionMenuOptions
741
742Describes the options for showing the action menu.
743
744**System capability**: SystemCapability.ArkUI.ArkUI.Full
745
746| Name                         | Type                                                        | Mandatory | Description                                                        |
747| ----------------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
748| 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. |
749| 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. |
750| showInSubWindow<sup>11+</sup> | boolean                                                      | No  | Whether to show the dialog box in a sub-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. |
751| 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. |
752
753## ActionMenuSuccessResponse
754
755Describes the action menu response result.
756
757**Atomic service API**: This API can be used in atomic services since API version 11.
758
759**System capability**: SystemCapability.ArkUI.ArkUI.Full
760
761| Name | Type  | Mandatory | Description                                    |
762| ----- | ------ | ---- | ---------------------------------------- |
763| index | number | Yes  | Index of the selected button in the **buttons** array, starting from **0**. |
764
765## CustomDialogOptions<sup>11+</sup>
766
767Defines the options of the custom dialog box. This API extends [BaseDialogOptions](#basedialogoptions11).
768
769**Atomic service API**: This API can be used in atomic services since API version 12.
770
771**System capability**: SystemCapability.ArkUI.ArkUI.Full
772
773| Name   | Type                                                   | Mandatory | Description                                                        |
774| ------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
775| 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. |
776| backgroundColor <sup>12+</sup>| [ResourceColor](arkui-ts/ts-types.md#resourcecolor)  | No | Background color of the dialog box. |
777| 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.|
778| 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.|
779| 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. |
780| 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. |
781| 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.|
782| 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.|
783| 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 |
784| backgroundBlurStyle<sup>12+</sup> | [BlurStyle](arkui-ts/ts-appendix-enums.md#blurstyle9)                 | No  | Background blur style of the dialog box.<br>Default value: **BlurStyle.COMPONENT_ULTRA_THICK** |
785
786## BaseDialogOptions<sup>11+</sup>
787
788Defines the options of the dialog box.
789
790**Atomic service API**: This API can be used in atomic services since API version 12.
791
792**System capability**: SystemCapability.ArkUI.ArkUI.Full
793
794| Name           | Type                                                        | Mandatory | Description                                                        |
795| --------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
796| 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**. |
797| 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**.|
798| 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 }** |
799| 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** |
800| showInSubWindow | boolean                                                      | No  | Whether to show the dialog box in a sub-window.<br>Default value: **false** |
801| 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. |
802|  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** |
803|  maskColor<sup>12+</sup> |        [ResourceColor](arkui-ts/ts-types.md#resourcecolor) | No   | Mask color.<br>Default value: **0x33000000**             |
804| 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.                              |
805| 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. |
806| 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. |
807| 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. |
808| 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**. |
809
810## DismissDialogAction<sup>12+</sup>
811
812Provides information about the action to dismiss the dialog box.
813
814**Atomic service API**: This API can be used in atomic services since API version 12.
815
816**System capability**: SystemCapability.ArkUI.ArkUI.Full
817
818### Attributes
819
820| Name   | Type                                                        | Readable | Writable | Description                                                        |
821| ------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ |
822| 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. |
823| reason  | [DismissReason](arkui-ts/ts-appendix-enums.md#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. |
824
825## Button
826
827Describes the menu item button in the action menu.
828
829**System capability**: SystemCapability.ArkUI.ArkUI.Full
830
831| Name   | Type                                      | Mandatory  | Description     |
832| ----- | ---------------------------------------- | ---- | ------- |
833| 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. |
834| 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. |
835| 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. |
836