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