# @ohos.promptAction (Prompt) The **PromptAction** module provides APIs for creating and showing toasts, dialog boxes, and action menus. > **NOTE** > > 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. > > 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. > > 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). It is recommended that, except for scenarios without a UI such as [ServiceExtension](../../application-models/serviceextensionability.md), you should use the dialog APIs provided by **UIContext**. > > 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. ## Modules to Import ```ts import { promptAction } from '@kit.ArkUI'; ``` ## promptAction.showToast showToast(options: ShowToastOptions): void Shows a toast. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.ArkUI.ArkUI.Full **Parameters** | Name | Type | Mandatory | Description | | ------- | ------------------------------------- | ---- | ------- | | options | [ShowToastOptions](#showtoastoptions) | Yes | Toast options.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md). | ID | Error Message| | --------- | ------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | | 100001 | Internal error. | **Example** ```ts import { promptAction } from '@kit.ArkUI' import { BusinessError } from '@kit.BasicServicesKit'; @Entry @Component struct toastExample { build() { Column() { Button('Show toast').fontSize(20) .onClick(() => { try { promptAction.showToast({ message: 'Hello World', duration: 2000 }); } catch (error) { let message = (error as BusinessError).message let code = (error as BusinessError).code console.error(`showToast args error code is ${code}, message is ${message}`); }; }) }.height('100%').width('100%').justifyContent(FlexAlign.Center) } } ``` Below is a toast in API version 11 and earlier versions. ![en-us_image_0001](figures/toast-api11.gif) Below is a toast in API version 12 and later versions. ![en-us_image_0001](figures/toast-api12.gif) ## promptAction.openToast13+ openToast(options: ShowToastOptions): Promise<number> Opens a toast. This API returns the toast ID. **Atomic service API**: This API can be used in atomic services since API version 13. **System capability**: SystemCapability.ArkUI.ArkUI.Full **Parameters** | Name | Type | Mandatory| Description | | ------- | ------------------------------------------------------------ | ---- | -------------- | | options | [ShowToastOptions](#showtoastoptions) | Yes | Toast options.| **Return value** | Type | Description | | ---------------- | ------------------------------------ | | Promise<number> | ID of the toast, which is required in **closeToast**.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | | 100001 | Internal error. | **Example** ```ts import { promptAction } from '@kit.ArkUI'; import { BusinessError } from '@kit.BasicServicesKit'; @Entry @Component struct toastExample { @State toastId: number = 0; build() { Column() { Button('Open Toast') .height(100) .onClick(() => { try { promptAction.openToast({ message: 'Toast Massage', duration: 10000, }).then((toastId: number) => { this.toastId = toastId; }); } catch (error) { let message = (error as BusinessError).message; let code = (error as BusinessError).code; console.error(`OpenToast error code is ${code}, message is ${message}`); }; }) Blank().height(50); Button('Close Toast') .height(100) .onClick(() => { try { promptAction.closeToast(this.toastId); } catch (error) { let message = (error as BusinessError).message; let code = (error as BusinessError).code; console.error(`CloseToast error code is ${code}, message is ${message}`); }; }) }.height('100%').width('100%').justifyContent(FlexAlign.Center) } } ``` ![toast-openclose](figures/toast-openclose.gif) ## promptAction.closeToast13+ closeToast(toastId: number): void Closes a toast. **Atomic service API**: This API can be used in atomic services since API version 13. **System capability**: SystemCapability.ArkUI.ArkUI.Full **Parameters** | Name | Type | Mandatory| Description | | ------- | ------ | ---- | ----------------------------- | | toastId | number | Yes | ID of the toast to close, which is returned by **openToast**.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | | 100001 | Internal error. | **Example** For details, see [promptAction.openToaset13](#promptactionopentoast13). ## promptAction.showDialog showDialog(options: ShowDialogOptions): Promise<ShowDialogSuccessResponse> Shows a dialog box. This API uses a promise to return the result asynchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.ArkUI.ArkUI.Full **Parameters** | Name | Type | Mandatory | Description | | ------- | --------------------------------------- | ---- | ------ | | options | [ShowDialogOptions](#showdialogoptions) | Yes | Dialog box options.| **Return value** | Type | Description | | ---------------------------------------- | -------- | | Promise<[ShowDialogSuccessResponse](#showdialogsuccessresponse)> | Promise used to return the dialog box response result.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md). | ID | Error Message| | --------- | ------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | | 100001 | Internal error. | **Example** ```ts import { promptAction } from '@kit.ArkUI' import { BusinessError } from '@kit.BasicServicesKit'; try { promptAction.showDialog({ title: 'Title Info', message: 'Message Info', buttons: [ { text: 'button1', color: '#000000' }, { text: 'button2', color: '#000000' } ], }) .then(data => { console.info('showDialog success, click button: ' + data.index); }) .catch((err:Error) => { console.info('showDialog error: ' + err); }) } catch (error) { let message = (error as BusinessError).message let code = (error as BusinessError).code console.error(`showDialog args error code is ${code}, message is ${message}`); }; ``` ![en-us_image_0002](figures/en-us_image_0002.gif) ## promptAction.showDialog showDialog(options: ShowDialogOptions, callback: AsyncCallback<ShowDialogSuccessResponse>):void Shows a dialog box. This API uses an asynchronous callback to return the result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.ArkUI.ArkUI.Full **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ------------ | | options | [ShowDialogOptions](#showdialogoptions) | Yes | Dialog box options.| | callback | AsyncCallback<[ShowDialogSuccessResponse](#showdialogsuccessresponse)> | Yes | Callback used to return the dialog box response result. | **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md). | ID | Error Message| | --------- | ------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | | 100001 | Internal error. | **Example** ```ts import { promptAction } from '@kit.ArkUI'; import { BusinessError } from '@kit.BasicServicesKit'; try { promptAction.showDialog({ title: 'showDialog Title Info', message: 'Message Info', buttons: [ { text: 'button1', color: '#000000' }, { text: 'button2', color: '#000000' } ] }, (err, data) => { if (err) { console.info('showDialog err: ' + err); return; } console.info('showDialog success callback, click button: ' + data.index); }); } catch (error) { let message = (error as BusinessError).message let code = (error as BusinessError).code console.error(`showDialog args error code is ${code}, message is ${message}`); }; ``` ![en-us_image_0004](figures/en-us_image_0004.gif) When the **showInSubWindow** attribute is set to **true**, the toast can be displayed outside the window. ```ts import { promptAction } from '@kit.ArkUI'; import { BusinessError } from '@kit.BasicServicesKit'; try { promptAction.showDialog({ title: 'showDialog Title Info', message: 'Message Info', isModal: true, showInSubWindow: true, buttons: [ { text: 'button1', color: '#000000' }, { text: 'button2', color: '#000000' } ] }, (err, data) => { if (err) { console.info('showDialog err: ' + err); return; } console.info('showDialog success callback, click button: ' + data.index); }); } catch (error) { let message = (error as BusinessError).message let code = (error as BusinessError).code console.error(`showDialog args error code is ${code}, message is ${message}`); }; ``` ![en-us_image_0002_showinsubwindow](figures/en-us_image_0002_showinsubwindow.jpg) ## promptAction.showActionMenu showActionMenu(options: ActionMenuOptions, callback: AsyncCallback<ActionMenuSuccessResponse>):void Shows an action menu. This API uses a callback to return the result asynchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.ArkUI.ArkUI.Full **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | --------- | | options | [ActionMenuOptions](#actionmenuoptions) | Yes | Action menu options. | | callback | AsyncCallback<[ActionMenuSuccessResponse](#actionmenusuccessresponse)> | Yes | Callback used to return the action menu response result.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md). | ID | Error Message| | --------- | ------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | | 100001 | Internal error. | **Example** ```ts import { promptAction } from '@kit.ArkUI'; import { BusinessError } from '@kit.BasicServicesKit'; try { promptAction.showActionMenu({ title: 'Title Info', buttons: [ { text: 'item1', color: '#666666' }, { text: 'item2', color: '#000000' }, ] }, (err, data) => { if (err) { console.info('showActionMenu err: ' + err); return; } console.info('showActionMenu success callback, click button: ' + data.index); }) } catch (error) { let message = (error as BusinessError).message let code = (error as BusinessError).code console.error(`showActionMenu args error code is ${code}, message is ${message}`); }; ``` ![en-us_image_0005](figures/en-us_image_0005.gif) ## promptAction.showActionMenu showActionMenu(options: ActionMenuOptions): Promise<ActionMenuSuccessResponse> Shows an action menu. This API uses a promise to return the result asynchronously. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.ArkUI.ArkUI.Full **Parameters** | Name | Type | Mandatory | Description | | ------- | --------------------------------------- | ---- | ------- | | options | [ActionMenuOptions](#actionmenuoptions) | Yes | Action menu options.| **Return value** | Type | Description | | ---------------------------------------- | ------- | | Promise<[ActionMenuSuccessResponse](#actionmenusuccessresponse)> | Promise used to return the action menu response result.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md). | ID | Error Message| | --------- | ------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | | 100001 | Internal error. | **Example** ```ts import { promptAction } from '@kit.ArkUI'; import { BusinessError } from '@kit.BasicServicesKit'; try { promptAction.showActionMenu({ title: 'showActionMenu Title Info', buttons: [ { text: 'item1', color: '#666666' }, { text: 'item2', color: '#000000' }, ] }) .then(data => { console.info('showActionMenu success, click button: ' + data.index); }) .catch((err:Error) => { console.info('showActionMenu error: ' + err); }) } catch (error) { let message = (error as BusinessError).message let code = (error as BusinessError).code console.error(`showActionMenu args error code is ${code}, message is ${message}`); }; ``` ![en-us_image_0006](figures/en-us_image_0006.gif) ## promptAction.openCustomDialog11+ openCustomDialog(options: CustomDialogOptions): Promise<number> Opens a custom dialog box. This API cannot be used in **ServiceExtension**. **isModal = true** and **showInSubWindow = true** cannot be used at the same time. By 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. **Atomic service API**: This API can be used in atomic services since API version 12. **System capability**: SystemCapability.ArkUI.ArkUI.Full **Parameters** | Name | Type | Mandatory| Description | | ------- | --------------------------------------------- | ---- | ------------------ | | options | [CustomDialogOptions](#customdialogoptions11) | Yes | Content of the custom dialog box.| **Return value** | Type | Description | | --------------------- | ------------------------------------- | | Promise<number> | ID of the custom dialog box, which can be used in **closeCustomDialog**.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md). | ID| Error Message | | -------- | ---------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | | 100001 | Internal error. | **Example** ```ts import { promptAction } from '@kit.ArkUI' @Entry @Component struct Index { private customDialogComponentId: number = 0 @Builder customDialogComponent() { Column() { Text('Toast').fontSize(30) Row({ space: 50 }) { Button("OK").onClick(() => { promptAction.closeCustomDialog(this.customDialogComponentId) }) Button("Cancel").onClick(() => { promptAction.closeCustomDialog(this.customDialogComponentId) }) } }.height(200).padding(5).justifyContent(FlexAlign.SpaceBetween) } build() { Row() { Column({ space: 20 }) { Text('In-component dialog box') .fontSize(30) .onClick(() => { promptAction.openCustomDialog({ builder: () => { this.customDialogComponent() }, onWillDismiss: (dismissDialogAction: DismissDialogAction) => { console.info("reason" + JSON.stringify(dismissDialogAction.reason)) console.log("dialog onWillDismiss") if (dismissDialogAction.reason == DismissReason.PRESS_BACK) { dismissDialogAction.dismiss() } if (dismissDialogAction.reason == DismissReason.TOUCH_OUTSIDE) { dismissDialogAction.dismiss() } } }).then((dialogId: number) => { this.customDialogComponentId = dialogId }) }) } .width('100%') } .height('100%') } } ``` This example demonstrates how to set styles of a dialog box, including the width, height, background color, and shadow. ```ts import { promptAction } from '@kit.ArkUI' let customDialogId: number = 0 @Builder function customDialogBuilder() { Column() { Text('Custom dialog Message').fontSize(10) Row() { Button("OK").onClick(() => { promptAction.closeCustomDialog(customDialogId) }) Blank().width(50) Button("Cancel").onClick(() => { promptAction.closeCustomDialog(customDialogId) }) } } } @Entry @Component struct Index { @State message: string = 'Hello World' @Builder customDialogComponent() { customDialogBuilder() } build() { Row() { Column() { Text(this.message) .fontSize(50) .fontWeight(FontWeight.Bold) .onClick(() => { promptAction.openCustomDialog({ builder: () => { this.customDialogComponent() }, keyboardAvoidMode: KeyboardAvoidMode.NONE, showInSubWindow: false, offset: { dx: 5, dy: 5 }, backgroundColor: 0xd9ffffff, cornerRadius: 20, width: '80%', height: 200, borderWidth: 1, borderStyle: BorderStyle.Dashed, // borderStyle must be used with borderWidth in pairs. borderColor: Color.Blue, // borderColor must be used with borderWidth in pairs. shadow: ({ radius: 20, color: Color.Grey, offsetX: 50, offsetY: 0 }), }).then((dialogId: number) => { customDialogId = dialogId }) }) } .width('100%') } .height('100%') } } ``` ![en-us_image_0007](figures/en-us_image_0007.gif) ## promptAction.closeCustomDialog11+ closeCustomDialog(dialogId: number): void Closes the specified custom dialog box. **Atomic service API**: This API can be used in atomic services since API version 12. **System capability**: SystemCapability.ArkUI.ArkUI.Full **Parameters** | Name | Type | Mandatory| Description | | -------- | ------ | ---- | -------------------------------- | | dialogId | number | Yes | ID of the custom dialog box to close. It is returned from **openCustomDialog**.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md). | ID| Error Message | | -------- | ---------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | | 100001 | Internal error. | **Example** See the example of [promptAction.openCustomDialog](#promptactionopencustomdialog11). ## ShowToastOptions Describes the options for showing the toast. **System capability**: SystemCapability.ArkUI.ArkUI.Full | Name | Type | Mandatory| Description | | ----------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | message | string \| [Resource](arkui-ts/ts-types.md#resource) | Yes | Text to display.
**NOTE**
The default font is **'Harmony Sans'**. Other fonts are not supported.
**Atomic service API**: This API can be used in atomic services since API version 11.| | 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.
**Atomic service API**: This API can be used in atomic services since API version 11.| | bottom | string \| number | No | Distance between the toast border and the bottom of the screen.
Default value: **80vp**
This parameter does not take effect after **Alignment** is set.
**Atomic service API**: This API can be used in atomic services since API version 11.| | showMode11+ | [ToastShowMode](#toastshowmode11) | No | Whether to show the toast above the application.
Default value: **ToastShowMode.DEFAULT**, which means to show the toast in the application.
**Atomic service API**: This API can be used in atomic services since API version 12.| | alignment12+ | [Alignment](arkui-ts/ts-appendix-enums.md#alignment) | No | Alignment mode.
Default value: **undefined**, indicating bottom start
**Atomic service API**: This API can be used in atomic services since API version 12. | | offset12+ | [Offset](arkui-ts/ts-types.md#offset) | No | Offset in the specified alignment mode.
Default value: **{dx:0, dy:0}**, indicating no offset
**Atomic service API**: This API can be used in atomic services since API version 12.| | backgroundColor12+ | [ResourceColor](arkui-ts/ts-types.md#resourcecolor) | No | Background color of the toast.
Default value: **Color.Transparent**
**NOTE**
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.
**Atomic service API**: This API can be used in atomic services since API version 12.| | textColor12+ | [ResourceColor](arkui-ts/ts-types.md#resourcecolor) | No | Font color of the toast.
Default value: **Color.Black**
**Atomic service API**: This API can be used in atomic services since API version 12.| | backgroundBlurStyle12+ | [BlurStyle](arkui-ts/ts-universal-attributes-background.md#blurstyle9) | No | Background blur style of the toast.
Default value: **BlurStyle.COMPONENT_ULTRA_THICK**
**NOTE**
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.
**Atomic service API**: This API can be used in atomic services since API version 12.| | shadow12+ | [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.
Default value: **ShadowStyle.OuterDefaultMD**
**Atomic service API**: This API can be used in atomic services since API version 12.| | enableHoverMode13+ | boolean | No | Whether to enable the hover state.
Default value: **False**, meaning not to enable the hover state.
**Atomic service API**: This API can be used in atomic services since API version 13.| | hoverModeArea13+ | [HoverModeAreaType](arkui-ts/ts-appendix-enums.md#hovermodeareatype13) | No | Display area of the toast in the hover state.
Default value: **HoverModeAreaType.BOTTOM_SCREEN**, indicating that the toast is displayed in the lower half screen
**Atomic service API**: This API can be used in atomic services since API version 13. | ## ToastShowMode11+ Describes the mode in which the toast is shown. **System capability**: SystemCapability.ArkUI.ArkUI.Full | Name | Value | Description | | -------- | ---- | ---------------------- | | DEFAULT | 0 | The toast is shown within the application. | | TOP_MOST | 1 | The toast is shown above the application.| ## ShowDialogOptions Describes the options for showing the dialog box. **System capability**: SystemCapability.ArkUI.ArkUI.Full | Name | Type | Mandatory| Description | | --------------------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | title | string \| [Resource](arkui-ts/ts-types.md#resource) | No | Title of the dialog box.
**Atomic service API**: This API can be used in atomic services since API version 11.| | message | string \| [Resource](arkui-ts/ts-types.md#resource) | No | Text body.
**Atomic service API**: This API can be used in atomic services since API version 11.| | buttons | Array<[Button](#button)> | No | Array of buttons in the dialog box. The array structure is {text:'button', color: '\#666666'}. More than one button is supported.
**Atomic service API**: This API can be used in atomic services since API version 11.| | alignment10+ | [DialogAlignment](arkui-ts/ts-methods-alert-dialog-box.md#dialogalignment) | No | Alignment mode of the dialog box in the vertical direction.
Default value: **DialogAlignment.Default**
**NOTE**
If **showInSubWindow** is set to **true** in **UIExtension**, the dialog box is aligned with the host window based on **UIExtension**.
**Atomic service API**: This API can be used in atomic services since API version 11.| | offset10+ | [Offset](arkui-ts/ts-types.md#offset) | No | Offset of the dialog box based on the **alignment** settings.
Default value: **{ dx: 0 , dy: 0 }**
**Atomic service API**: This API can be used in atomic services since API version 11.| | maskRect10+ | [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.
Default value: **{ x: 0, y: 0, width: '100%', height: '100%' }**
**NOTE**
**maskRect** does not take effect when **showInSubWindow** is set to **true**.
**Atomic service API**: This API can be used in atomic services since API version 11.| | showInSubWindow11+ | boolean | No | Whether to show the dialog box in a sub-window.
Default value: **false**
**NOTE**
A dialog box whose **showInSubWindow** attribute is **true** cannot trigger the display of another dialog box whose **showInSubWindow** attribute is also **true**.
**Atomic service API**: This API can be used in atomic services since API version 12.| | isModal11+ | 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.
Default value: **true**
**Atomic service API**: This API can be used in atomic services since API version 12.| | backgroundColor12+ | [ResourceColor](arkui-ts/ts-types.md#resourcecolor) | No | Background color of the dialog box.
Default value: **Color.Transparent**
**NOTE**
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.
**Atomic service API**: This API can be used in atomic services since API version 12.| | backgroundBlurStyle12+ | [BlurStyle](arkui-ts/ts-universal-attributes-background.md#blurstyle9) | No | Background blur style of the dialog box.
Default value: **BlurStyle.COMPONENT_ULTRA_THICK**
**NOTE**
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.
**Atomic service API**: This API can be used in atomic services since API version 12.| | shadow12+ | [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.
Default value on 2-in-1 devices: **ShadowStyle.OUTER_FLOATING_MD** when the dialog box is focused and **ShadowStyle.OUTER_FLOATING_SM** otherwise
**Atomic service API**: This API can be used in atomic services since API version 12.| | enableHoverMode13+ | boolean | No | Whether to enable the hover state.
Default value: **false**, meaning not to enable the hover state. | | hoverModeArea13+ | [HoverModeAreaType](arkui-ts/ts-appendix-enums.md#hovermodeareatype13) | No | Display area of the dialog box in the hover state.
Default value: **HoverModeAreaType.BOTTOM_SCREEN**| ## ShowDialogSuccessResponse Describes the dialog box response result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.ArkUI.ArkUI.Full | Name | Type | Mandatory| Description | | ----- | ------ | ---- | ------------------------------- | | index | number | Yes | Index of the selected button in the **buttons** array.| ## ActionMenuOptions Describes the options for showing the action menu. **System capability**: SystemCapability.ArkUI.ArkUI.Full | Name | Type | Mandatory| Description | | ----------------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | title | string \| [Resource](arkui-ts/ts-types.md#resource) | No | Title of the dialog box.
**Atomic service API**: This API can be used in atomic services since API version 11.| | 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.
**Atomic service API**: This API can be used in atomic services since API version 11.| | showInSubWindow11+ | boolean | No | Whether to show the dialog box in a sub-window.
Default value: **false**, indicating that the dialog box is not displayed in the subwindow
**NOTE**
- A dialog box whose **showInSubWindow** attribute is **true** cannot trigger the display of another dialog box whose **showInSubWindow** attribute is also **true**.
- If **showInSubWindow** is set to **true** in **UIExtension**, the dialog box is aligned with the host window based on **UIExtension**.
**Atomic service API**: This API can be used in atomic services since API version 12.| | isModal11+ | 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.
Default value: **true**
**Atomic service API**: This API can be used in atomic services since API version 12.| ## ActionMenuSuccessResponse Describes the action menu response result. **Atomic service API**: This API can be used in atomic services since API version 11. **System capability**: SystemCapability.ArkUI.ArkUI.Full | Name | Type | Mandatory| Description | | ----- | ------ | ---- | ---------------------------------------- | | index | number | Yes | Index of the selected button in the **buttons** array, starting from **0**.| ## CustomDialogOptions11+ Defines the options of the custom dialog box. This API extends [BaseDialogOptions](#basedialogoptions11). **Atomic service API**: This API can be used in atomic services since API version 12. **System capability**: SystemCapability.ArkUI.ArkUI.Full | Name | Type | Mandatory| Description | | ------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | | builder | [CustomBuilder](arkui-ts/ts-types.md#custombuilder8) | Yes | Content of the custom dialog box.
**NOTE**
The builder needs to be assigned an arrow function in the following format: () => { this.XXX() }, where XXX indicates the internal builder name.
If you are working with a global builder, you need to call it within a local builder within a component.
The aspect ratio of the root node of a builder is relative to the size of the dialog box container.
The aspect ratio of a non-root node is relative to the size of its parent node.
**Atomic service API**: This API can be used in atomic services since API version 12.| | backgroundColor 12+| [ResourceColor](arkui-ts/ts-types.md#resourcecolor) | No| Background color of the dialog box.
Default value: **Color.Transparent**
**NOTE**
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.| | cornerRadius12+| [Dimension](arkui-ts/ts-types.md#dimension10) \| [BorderRadiuses](arkui-ts/ts-types.md#borderradiuses9) | No| Radius of the rounded corners of the background.
You can set separate radiuses for the four rounded corners.
Default value: **{ topLeft: '32vp', topRight: '32vp', bottomLeft: '32vp', bottomRight: '32vp' }**
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.
When set to a percentage, the value defines the radius as a percentage of the parent component's width or height.| | borderWidth12+| [Dimension](arkui-ts/ts-types.md#dimension10) \| [EdgeWidths](arkui-ts/ts-types.md#edgewidths9) | No| Border width of the dialog box.
You can set the width for all four sides or set separate widths for individual sides.
Default value: **0**
When set to a percentage, the value defines the border width as a percentage of the parent dialog box's width.
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.| | borderColor12+ | [ResourceColor](arkui-ts/ts-types.md#resourcecolor) \| [EdgeColors](arkui-ts/ts-types.md#edgecolors9) | No| Border color of the dialog box.
Default value: **Color.Black**
**borderColor** must be used with **borderWidth** in pairs.| | borderStyle12+ | [BorderStyle](arkui-ts/ts-appendix-enums.md#borderstyle) \| [EdgeStyles](arkui-ts/ts-types.md#edgestyles9) | No| Border style of the dialog box.
Default value: **BorderStyle.Solid**
**borderStyle** must be used with **borderWidth** in pairs.| | width12+ | [Dimension](arkui-ts/ts-types.md#dimension10) | No | Width of the dialog box.
**NOTE**
- Default maximum width of the dialog box: 400 vp
- 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.| | height12+ | [Dimension](arkui-ts/ts-types.md#dimension10) | No | Height of the dialog box.
**NOTE**
- Default maximum height of the dialog box: 0.9 x (Window height – Safe area)
- 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.| | shadow12+| [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.
Default value on 2-in-1 devices: **ShadowStyle.OUTER_FLOATING_MD** when the dialog box is focused and **ShadowStyle.OUTER_FLOATING_SM** otherwise| | backgroundBlurStyle12+ | [BlurStyle](arkui-ts/ts-universal-attributes-background.md#blurstyle9) | No | Background blur style of the dialog box.
Default value: **BlurStyle.COMPONENT_ULTRA_THICK**
**NOTE**
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.| ## BaseDialogOptions11+ Defines the options of the dialog box. **Atomic service API**: This API can be used in atomic services since API version 12. **System capability**: SystemCapability.ArkUI.ArkUI.Full | Name | Type | Mandatory| Description | | --------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | maskRect | [Rectangle](arkui-ts/ts-methods-alert-dialog-box.md#rectangle8) | No | Mask area.
Default value: **{ x: 0, y: 0, width: '100%', height: '100%' }**
**NOTE**
**maskRect** does not take effect when **showInSubWindow** is set to **true**.| | alignment | [DialogAlignment](arkui-ts/ts-methods-alert-dialog-box.md#dialogalignment) | No | Alignment mode of the dialog box in the vertical direction.
Default value: **DialogAlignment.Default**
**NOTE**
If **showInSubWindow** is set to **true** in **UIExtension**, the dialog box is aligned with the host window based on **UIExtension**.| | offset | [Offset](arkui-ts/ts-types.md#offset) | No | Offset of the dialog box based on the **alignment** settings.
Default value: **{ dx: 0 , dy: 0 }**| | 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.
Default value: **true**| | showInSubWindow | boolean | No | Whether to show the dialog box in a sub-window.
Default value: **false**| | onWillDismiss12+ | Callback<[DismissDialogAction](#dismissdialogaction12)> | No| Callback for interactive dismissal of the dialog box.
**NOTE**
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**.
2. In the **onWillDismiss** callback, another **onWillDismiss** callback is not allowed.| | autoCancel12+ | 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.
Default value: **true**| | maskColor12+ | [ResourceColor](arkui-ts/ts-types.md#resourcecolor) | No | Mask color.
Default value: **0x33000000** | | transition12+ | [TransitionEffect](arkui-ts/ts-transition-animation-component.md#transitioneffect10) | No | Transition effect for the entrance and exit of the dialog box.
**NOTE**
1. If this parameter is not set, the default effect is used.
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.
3. Touching the Back button during the exit animation does not affect the animation playback. Touching the Back button again closes the application. | | onDidAppear12+ | () => void | No| Event callback when the dialog box appears.
**NOTE**
1. The normal timing sequence is as follows: onWillAppear > onDidAppear > (onDateAccept/onCancel/onDateChange) > onWillDisappear > onDidDisappear.
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.
3. If the user dismisses the dialog box immediately after it appears, **onWillDisappear** is invoked before **onDidAppear**.
4. If the dialog box is dismissed before its entrance animation is finished, this callback is not invoked.| | onDidDisappear12+ | () => void | No| Event callback when the dialog box disappears.
**NOTE**
The normal timing sequence is as follows: onWillAppear > onDidAppear > (onDateAccept/onCancel/onDateChange) > onWillDisappear > onDidDisappear.| | onWillAppear12+ | () => void | No| Event callback when the dialog box is about to appear.
**NOTE**
1. The normal timing sequence is as follows: onWillAppear > onDidAppear > (onDateAccept/onCancel/onDateChange) > onWillDisappear > onDidDisappear.
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.| | onWillDisappear12+ | () => void | No| Event callback when the dialog box is about to disappear.
**NOTE**
1. The normal timing sequence is as follows: onWillAppear > onDidAppear > (onDateAccept/onCancel/onDateChange) > onWillDisappear > onDidDisappear.
2. If the user dismisses the dialog box immediately after it appears, **onWillDisappear** is invoked before **onDidAppear**.| | keyboardAvoidMode12+ | [KeyboardAvoidMode](#keyboardavoidmode12) | No| How the dialog box avoids the soft keyboard when it is brought up.
Default value: **KeyboardAvoidMode.DEFAULT**
**Atomic service API**: This API can be used in atomic services since API version 12.| | enableHoverMode13+ | boolean | No | Whether to enable the hover state.
Default value: **false**, meaning not to enable the hover state.| | hoverModeArea13+ | [HoverModeAreaType](arkui-ts/ts-appendix-enums.md#hovermodeareatype13) | No | Display area of the dialog box in the hover state.
Default value: **HoverModeAreaType.BOTTOM_SCREEN**| ## DismissDialogAction12+ Provides information about the action to dismiss the dialog box. **Atomic service API**: This API can be used in atomic services since API version 12. **System capability**: SystemCapability.ArkUI.ArkUI.Full ### Attributes | Name | Type | Readable| Writable| Description | | ------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ | | dismiss | Callback<void> | No | No | Callback for dismissing the dialog box. This API is called only when the dialog box needs to be exited.| | 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.| ## DismissReason12+ **Atomic service API**: This API can be used in atomic services since API version 12. **System capability**: SystemCapability.ArkUI.ArkUI.Full | Name | Value | Description | | ------------- | ---- | ------------------------------------------------------------ | | PRESS_BACK | 0 | Touching the Back button, swiping left or right on the screen, or pressing the Esc key. | | TOUCH_OUTSIDE | 1 | Touching the mask. | | CLOSE_BUTTON | 2 | Touching the Close button. | | SLIDE_DOWN | 3 | Sliding down.
**NOTE**
This API is effective only in [sheet transition](./arkui-ts/ts-universal-attributes-sheet-transition.md).| ## KeyboardAvoidMode12+ **Atomic service API**: This API can be used in atomic services since API version 12. **System capability**: SystemCapability.ArkUI.ArkUI.Full | Name | Value | Description | | ------- | ---- | ------------------------------------------------ | | DEFAULT | 0 | Automatically avoids the soft keyboard and compresses the height when reaching the maximum limit.| | NONE | 1 | Does not avoid the soft keyboard. | ## Button Describes the menu item button in the action menu. **System capability**: SystemCapability.ArkUI.ArkUI.Full | Name | Type | Mandatory | Description | | ----- | ---------------------------------------- | ---- | ------- | | text | string \| [Resource](arkui-ts/ts-types.md#resource)| Yes | Button text.
**Atomic service API**: This API can be used in atomic services since API version 11.| | color | string \| [Resource](arkui-ts/ts-types.md#resource) | Yes | Text color of the button.
**Atomic service API**: This API can be used in atomic services since API version 11.| | primary12+ | 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.
**Atomic service API**: This API can be used in atomic services since API version 12.|