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). It is recommended that, except for scenarios without a UI<!--Del--> such as [ServiceExtension](../../application-models/serviceextensionability.md)<!--DelEnd-->, you should use the dialog APIs provided by **UIContext**. 12> 13> Since API version 10, you can use the [getPromptAction](js-apis-arkui-UIContext.md#getpromptaction) API in [UIContext](js-apis-arkui-UIContext.md#uicontext) to obtain the [PromptAction](js-apis-arkui-UIContext.md#promptaction) object associated with the current UI context. 14 15## Modules to Import 16 17```ts 18import { promptAction } from '@kit.ArkUI'; 19``` 20 21## promptAction.showToast 22 23showToast(options: ShowToastOptions): void 24 25Shows a toast. 26 27**Atomic service API**: This API can be used in atomic services since API version 11. 28 29**System capability**: SystemCapability.ArkUI.ArkUI.Full 30 31**Parameters** 32 33| Name | Type | Mandatory | Description | 34| ------- | ------------------------------------- | ---- | ------- | 35| options | [ShowToastOptions](#showtoastoptions) | Yes | Toast options.| 36 37**Error codes** 38 39For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md). 40 41| ID | Error Message| 42| --------- | ------- | 43| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | 44| 100001 | Internal error. | 45 46**Example** 47 48```ts 49import { promptAction } from '@kit.ArkUI' 50import { BusinessError } from '@kit.BasicServicesKit'; 51 52@Entry 53@Component 54struct toastExample { 55 build() { 56 Column() { 57 Button('Show toast').fontSize(20) 58 .onClick(() => { 59 try { 60 promptAction.showToast({ 61 message: 'Hello World', 62 duration: 2000 63 }); 64 } catch (error) { 65 let message = (error as BusinessError).message 66 let code = (error as BusinessError).code 67 console.error(`showToast args error code is ${code}, message is ${message}`); 68 }; 69 }) 70 }.height('100%').width('100%').justifyContent(FlexAlign.Center) 71 } 72} 73``` 74Below is a toast in API version 11 and earlier versions. 75 76 77 78Below is a toast in API version 12 and later versions. 79 80 81 82## promptAction.openToast<sup>13+</sup> 83 84openToast(options: ShowToastOptions): Promise<number> 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 13. 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<number> | ID of the toast, which is required in **closeToast**.| 103 104**Error codes** 105 106For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md). 107 108| ID| Error Message | 109| -------- | ------------------------------------------------------------ | 110| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | 111| 100001 | Internal error. | 112 113**Example** 114 115```ts 116import { promptAction } from '@kit.ArkUI'; 117import { BusinessError } from '@kit.BasicServicesKit'; 118@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 158 159## promptAction.closeToast<sup>13+</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 13. 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 parameters types; 3. Parameter verification failed. | 182| 100001 | Internal error. | 183 184**Example** 185 186For details, see [promptAction.openToaset13](#promptactionopentoast13). 187 188## promptAction.showDialog 189 190showDialog(options: ShowDialogOptions): Promise<ShowDialogSuccessResponse> 191 192Shows a dialog box. This API uses a promise to return the result asynchronously. 193 194**Atomic service API**: This API can be used in atomic services since API version 11. 195 196**System capability**: SystemCapability.ArkUI.ArkUI.Full 197 198**Parameters** 199 200| Name | Type | Mandatory | Description | 201| ------- | --------------------------------------- | ---- | ------ | 202| options | [ShowDialogOptions](#showdialogoptions) | Yes | Dialog box options.| 203 204**Return value** 205 206| Type | Description | 207| ---------------------------------------- | -------- | 208| Promise<[ShowDialogSuccessResponse](#showdialogsuccessresponse)> | Promise used to return the dialog box response result.| 209 210**Error codes** 211 212For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md). 213 214| ID | Error Message| 215| --------- | ------- | 216| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | 217| 100001 | Internal error. | 218 219**Example** 220 221```ts 222import { promptAction } from '@kit.ArkUI' 223import { BusinessError } from '@kit.BasicServicesKit'; 224 225try { 226 promptAction.showDialog({ 227 title: 'Title Info', 228 message: 'Message Info', 229 buttons: [ 230 { 231 text: 'button1', 232 color: '#000000' 233 }, 234 { 235 text: 'button2', 236 color: '#000000' 237 } 238 ], 239 }) 240 .then(data => { 241 console.info('showDialog success, click button: ' + data.index); 242 }) 243 .catch((err:Error) => { 244 console.info('showDialog error: ' + err); 245 }) 246} catch (error) { 247 let message = (error as BusinessError).message 248 let code = (error as BusinessError).code 249 console.error(`showDialog args error code is ${code}, message is ${message}`); 250}; 251``` 252 253 254 255## promptAction.showDialog 256 257showDialog(options: ShowDialogOptions, callback: AsyncCallback<ShowDialogSuccessResponse>):void 258 259Shows a dialog box. This API uses an asynchronous callback to return the result. 260 261**Atomic service API**: This API can be used in atomic services since API version 11. 262 263**System capability**: SystemCapability.ArkUI.ArkUI.Full 264 265**Parameters** 266 267| Name | Type | Mandatory | Description | 268| -------- | ---------------------------------------- | ---- | ------------ | 269| options | [ShowDialogOptions](#showdialogoptions) | Yes | Dialog box options.| 270| callback | AsyncCallback<[ShowDialogSuccessResponse](#showdialogsuccessresponse)> | Yes | Callback used to return the dialog box response result. | 271 272**Error codes** 273 274For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md). 275 276| ID | Error Message| 277| --------- | ------- | 278| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | 279| 100001 | Internal error. | 280 281**Example** 282 283```ts 284import { promptAction } from '@kit.ArkUI'; 285import { BusinessError } from '@kit.BasicServicesKit'; 286 287try { 288 promptAction.showDialog({ 289 title: 'showDialog Title Info', 290 message: 'Message Info', 291 buttons: [ 292 { 293 text: 'button1', 294 color: '#000000' 295 }, 296 { 297 text: 'button2', 298 color: '#000000' 299 } 300 ] 301 }, (err, data) => { 302 if (err) { 303 console.info('showDialog err: ' + err); 304 return; 305 } 306 console.info('showDialog success callback, click button: ' + data.index); 307 }); 308} catch (error) { 309 let message = (error as BusinessError).message 310 let code = (error as BusinessError).code 311 console.error(`showDialog args error code is ${code}, message is ${message}`); 312}; 313``` 314 315 316 317When the **showInSubWindow** attribute is set to **true**, the toast can be displayed outside the window. 318 319```ts 320import { promptAction } from '@kit.ArkUI'; 321import { BusinessError } from '@kit.BasicServicesKit'; 322 323try { 324 promptAction.showDialog({ 325 title: 'showDialog Title Info', 326 message: 'Message Info', 327 isModal: true, 328 showInSubWindow: true, 329 buttons: [ 330 { 331 text: 'button1', 332 color: '#000000' 333 }, 334 { 335 text: 'button2', 336 color: '#000000' 337 } 338 ] 339 }, (err, data) => { 340 if (err) { 341 console.info('showDialog err: ' + err); 342 return; 343 } 344 console.info('showDialog success callback, click button: ' + data.index); 345 }); 346} catch (error) { 347 let message = (error as BusinessError).message 348 let code = (error as BusinessError).code 349 console.error(`showDialog args error code is ${code}, message is ${message}`); 350}; 351``` 352 353 354 355 356 357## promptAction.showActionMenu 358 359showActionMenu(options: ActionMenuOptions, callback: AsyncCallback<ActionMenuSuccessResponse>):void 360 361Shows an action menu. This API uses a callback to return the result asynchronously. 362 363**Atomic service API**: This API can be used in atomic services since API version 11. 364 365**System capability**: SystemCapability.ArkUI.ArkUI.Full 366 367**Parameters** 368 369| Name | Type | Mandatory | Description | 370| -------- | ---------------------------------------- | ---- | --------- | 371| options | [ActionMenuOptions](#actionmenuoptions) | Yes | Action menu options. | 372| callback | AsyncCallback<[ActionMenuSuccessResponse](#actionmenusuccessresponse)> | Yes | Callback used to return the action menu response result.| 373 374**Error codes** 375 376For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md). 377 378| ID | Error Message| 379| --------- | ------- | 380| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | 381| 100001 | Internal error. | 382 383**Example** 384 385```ts 386import { promptAction } from '@kit.ArkUI'; 387import { BusinessError } from '@kit.BasicServicesKit'; 388 389try { 390 promptAction.showActionMenu({ 391 title: 'Title Info', 392 buttons: [ 393 { 394 text: 'item1', 395 color: '#666666' 396 }, 397 { 398 text: 'item2', 399 color: '#000000' 400 }, 401 ] 402 }, (err, data) => { 403 if (err) { 404 console.info('showActionMenu err: ' + err); 405 return; 406 } 407 console.info('showActionMenu success callback, click button: ' + data.index); 408 }) 409} catch (error) { 410 let message = (error as BusinessError).message 411 let code = (error as BusinessError).code 412 console.error(`showActionMenu args error code is ${code}, message is ${message}`); 413}; 414``` 415 416 417 418## promptAction.showActionMenu 419 420showActionMenu(options: ActionMenuOptions): Promise<ActionMenuSuccessResponse> 421 422Shows an action menu. This API uses a promise to return the result asynchronously. 423 424**Atomic service API**: This API can be used in atomic services since API version 11. 425 426**System capability**: SystemCapability.ArkUI.ArkUI.Full 427 428**Parameters** 429 430| Name | Type | Mandatory | Description | 431| ------- | --------------------------------------- | ---- | ------- | 432| options | [ActionMenuOptions](#actionmenuoptions) | Yes | Action menu options.| 433 434**Return value** 435 436| Type | Description | 437| ---------------------------------------- | ------- | 438| Promise<[ActionMenuSuccessResponse](#actionmenusuccessresponse)> | Promise used to return the action menu response result.| 439 440**Error codes** 441 442For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md). 443 444| ID | Error Message| 445| --------- | ------- | 446| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | 447| 100001 | Internal error. | 448 449**Example** 450 451```ts 452import { promptAction } from '@kit.ArkUI'; 453import { BusinessError } from '@kit.BasicServicesKit'; 454 455try { 456 promptAction.showActionMenu({ 457 title: 'showActionMenu Title Info', 458 buttons: [ 459 { 460 text: 'item1', 461 color: '#666666' 462 }, 463 { 464 text: 'item2', 465 color: '#000000' 466 }, 467 ] 468 }) 469 .then(data => { 470 console.info('showActionMenu success, click button: ' + data.index); 471 }) 472 .catch((err:Error) => { 473 console.info('showActionMenu error: ' + err); 474 }) 475} catch (error) { 476 let message = (error as BusinessError).message 477 let code = (error as BusinessError).code 478 console.error(`showActionMenu args error code is ${code}, message is ${message}`); 479}; 480``` 481 482 483 484## promptAction.openCustomDialog<sup>11+</sup> 485 486openCustomDialog(options: CustomDialogOptions): Promise<number> 487 488Opens a custom dialog box. 489 490<!--Del-->This API cannot be used in **ServiceExtension**.<!--DelEnd--> 491 492**isModal = true** and **showInSubWindow = true** cannot be used at the same time. 493 494By 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. 495 496**Atomic service API**: This API can be used in atomic services since API version 12. 497 498**System capability**: SystemCapability.ArkUI.ArkUI.Full 499 500**Parameters** 501 502| Name | Type | Mandatory| Description | 503| ------- | --------------------------------------------- | ---- | ------------------ | 504| options | [CustomDialogOptions](#customdialogoptions11) | Yes | Content of the custom dialog box.| 505 506**Return value** 507 508| Type | Description | 509| --------------------- | ------------------------------------- | 510| Promise<number> | ID of the custom dialog box, which can be used in **closeCustomDialog**.| 511 512**Error codes** 513 514For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md). 515 516| ID| Error Message | 517| -------- | ---------------------------------- | 518| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | 519| 100001 | Internal error. | 520 521**Example** 522 523```ts 524import { promptAction } from '@kit.ArkUI' 525 526@Entry 527@Component 528struct Index { 529 private customDialogComponentId: number = 0 530 531 @Builder customDialogComponent() { 532 Column() { 533 Text('Toast').fontSize(30) 534 Row({ space: 50 }) { 535 Button("OK").onClick(() => { 536 promptAction.closeCustomDialog(this.customDialogComponentId) 537 }) 538 Button("Cancel").onClick(() => { 539 promptAction.closeCustomDialog(this.customDialogComponentId) 540 }) 541 } 542 }.height(200).padding(5).justifyContent(FlexAlign.SpaceBetween) 543 } 544 545 build() { 546 Row() { 547 Column({ space: 20 }) { 548 Text('In-component dialog box') 549 .fontSize(30) 550 .onClick(() => { 551 promptAction.openCustomDialog({ 552 builder: () => { 553 this.customDialogComponent() 554 }, 555 onWillDismiss: (dismissDialogAction: DismissDialogAction) => { 556 console.info("reason" + JSON.stringify(dismissDialogAction.reason)) 557 console.log("dialog onWillDismiss") 558 if (dismissDialogAction.reason == DismissReason.PRESS_BACK) { 559 dismissDialogAction.dismiss() 560 } 561 if (dismissDialogAction.reason == DismissReason.TOUCH_OUTSIDE) { 562 dismissDialogAction.dismiss() 563 } 564 } 565 }).then((dialogId: number) => { 566 this.customDialogComponentId = dialogId 567 }) 568 }) 569 } 570 .width('100%') 571 } 572 .height('100%') 573 } 574} 575 576``` 577This example demonstrates how to set styles of a dialog box, including the width, height, background color, and shadow. 578```ts 579import { promptAction } from '@kit.ArkUI' 580 581let customDialogId: number = 0 582 583@Builder 584function customDialogBuilder() { 585 Column() { 586 Text('Custom dialog Message').fontSize(10) 587 Row() { 588 Button("OK").onClick(() => { 589 promptAction.closeCustomDialog(customDialogId) 590 }) 591 Blank().width(50) 592 Button("Cancel").onClick(() => { 593 promptAction.closeCustomDialog(customDialogId) 594 }) 595 } 596 } 597} 598 599@Entry 600@Component 601struct Index { 602 @State message: string = 'Hello World' 603 604 @Builder 605 customDialogComponent() { 606 customDialogBuilder() 607 } 608 609 build() { 610 Row() { 611 Column() { 612 Text(this.message) 613 .fontSize(50) 614 .fontWeight(FontWeight.Bold) 615 .onClick(() => { 616 promptAction.openCustomDialog({ 617 builder: () => { 618 this.customDialogComponent() 619 }, 620 keyboardAvoidMode: KeyboardAvoidMode.NONE, 621 showInSubWindow: false, 622 offset: { dx: 5, dy: 5 }, 623 backgroundColor: 0xd9ffffff, 624 cornerRadius: 20, 625 width: '80%', 626 height: 200, 627 borderWidth: 1, 628 borderStyle: BorderStyle.Dashed, // borderStyle must be used with borderWidth in pairs. 629 borderColor: Color.Blue, // borderColor must be used with borderWidth in pairs. 630 shadow: ({ 631 radius: 20, 632 color: Color.Grey, 633 offsetX: 50, 634 offsetY: 0 635 }), 636 }).then((dialogId: number) => { 637 customDialogId = dialogId 638 }) 639 }) 640 } 641 .width('100%') 642 } 643 .height('100%') 644 } 645} 646``` 647 648 649## promptAction.closeCustomDialog<sup>11+</sup> 650 651closeCustomDialog(dialogId: number): void 652 653Closes the specified custom dialog box. 654 655**Atomic service API**: This API can be used in atomic services since API version 12. 656 657**System capability**: SystemCapability.ArkUI.ArkUI.Full 658 659**Parameters** 660 661| Name | Type | Mandatory| Description | 662| -------- | ------ | ---- | -------------------------------- | 663| dialogId | number | Yes | ID of the custom dialog box to close. It is returned from **openCustomDialog**.| 664 665**Error codes** 666 667For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md). 668 669| ID| Error Message | 670| -------- | ---------------------------------- | 671| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. | 672| 100001 | Internal error. | 673 674**Example** 675 676See the example of [promptAction.openCustomDialog](#promptactionopencustomdialog11). 677 678## ShowToastOptions 679 680Describes the options for showing the toast. 681 682**System capability**: SystemCapability.ArkUI.ArkUI.Full 683 684| Name | Type | Mandatory| Description | 685| ----------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 686| 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.| 687| 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.| 688| 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.| 689| 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.| 690| 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. | 691| 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.| 692| backgroundColor<sup>12+</sup> | [ResourceColor](arkui-ts/ts-types.md#resourcecolor) | No | Background color of the toast.<br>Default value: **Color.Transparent**<br>**NOTE**<br>When **backgroundColor** is set to a non-transparent color, **backgroundBlurStyle** must be set to **BlurStyle.NONE**; otherwise, the color display may not meet the expected effect.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 693| textColor<sup>12+</sup> | [ResourceColor](arkui-ts/ts-types.md#resourcecolor) | No | Font color of the toast.<br>Default value: **Color.Black**<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 694| backgroundBlurStyle<sup>12+</sup> | [BlurStyle](arkui-ts/ts-universal-attributes-background.md#blurstyle9) | No | Background blur style of the toast.<br>Default value: **BlurStyle.COMPONENT_ULTRA_THICK**<br>**NOTE**<br>Setting this parameter to **BlurStyle.NONE** disables the background blur. When **backgroundBlurStyle** is set to a value other than **NONE**, do not set **backgroundColor**. If you do, the color display may not produce the expected visual effect.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 695| 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**<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 696| enableHoverMode<sup>13+</sup> | boolean | No | Whether to enable the hover state.<br>Default value: **False**, meaning not to enable the hover state.<br>**Atomic service API**: This API can be used in atomic services since API version 13.| 697| hoverModeArea<sup>13+</sup> | [HoverModeAreaType](arkui-ts/ts-appendix-enums.md#hovermodeareatype13) | No | Display area of the toast in the hover state.<br>Default value: **HoverModeAreaType.BOTTOM_SCREEN**, indicating that the toast is displayed in the lower half screen<br>**Atomic service API**: This API can be used in atomic services since API version 13. | 698 699## ToastShowMode<sup>11+</sup> 700 701Describes the mode in which the toast is shown. 702 703**System capability**: SystemCapability.ArkUI.ArkUI.Full 704 705| Name | Value | Description | 706| -------- | ---- | ---------------------- | 707| DEFAULT | 0 | The toast is shown within the application. | 708| TOP_MOST | 1 | The toast is shown above the application.| 709 710## ShowDialogOptions 711 712Describes the options for showing the dialog box. 713 714**System capability**: SystemCapability.ArkUI.ArkUI.Full 715 716| Name | Type | Mandatory| Description | 717| --------------------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 718| 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.| 719| 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.| 720| 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.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 721| 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.| 722| 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.| 723| 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.| 724| 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.| 725| 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.| 726| backgroundColor<sup>12+</sup> | [ResourceColor](arkui-ts/ts-types.md#resourcecolor) | No | Background color of the dialog box.<br>Default value: **Color.Transparent**<br>**NOTE**<br>When **backgroundColor** is set to a non-transparent color, **backgroundBlurStyle** must be set to **BlurStyle.NONE**; otherwise, the color display may not meet the expected effect.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 727| backgroundBlurStyle<sup>12+</sup> | [BlurStyle](arkui-ts/ts-universal-attributes-background.md#blurstyle9) | No | Background blur style of the dialog box.<br>Default value: **BlurStyle.COMPONENT_ULTRA_THICK**<br>**NOTE**<br>Setting this parameter to **BlurStyle.NONE** disables the background blur. When **backgroundBlurStyle** is set to a value other than **NONE**, do not set **backgroundColor**. If you do, the color display may not produce the expected visual effect.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 728| 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.| 729| enableHoverMode<sup>13+</sup> | boolean | No | Whether to enable the hover state.<br>Default value: **false**, meaning not to enable the hover state. | 730| hoverModeArea<sup>13+</sup> | [HoverModeAreaType](arkui-ts/ts-appendix-enums.md#hovermodeareatype13) | No | Display area of the dialog box in the hover state.<br>Default value: **HoverModeAreaType.BOTTOM_SCREEN**| 731 732## ShowDialogSuccessResponse 733 734Describes the dialog box response result. 735 736**Atomic service API**: This API can be used in atomic services since API version 11. 737 738**System capability**: SystemCapability.ArkUI.ArkUI.Full 739 740| Name | Type | Mandatory| Description | 741| ----- | ------ | ---- | ------------------------------- | 742| index | number | Yes | Index of the selected button in the **buttons** array.| 743 744## ActionMenuOptions 745 746Describes the options for showing the action menu. 747 748**System capability**: SystemCapability.ArkUI.ArkUI.Full 749 750| Name | Type | Mandatory| Description | 751| ----------------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 752| 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.| 753| 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.| 754| 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.| 755| 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.| 756 757## ActionMenuSuccessResponse 758 759Describes the action menu response result. 760 761**Atomic service API**: This API can be used in atomic services since API version 11. 762 763**System capability**: SystemCapability.ArkUI.ArkUI.Full 764 765| Name | Type | Mandatory| Description | 766| ----- | ------ | ---- | ---------------------------------------- | 767| index | number | Yes | Index of the selected button in the **buttons** array, starting from **0**.| 768 769## CustomDialogOptions<sup>11+</sup> 770 771Defines the options of the custom dialog box. This API extends [BaseDialogOptions](#basedialogoptions11). 772 773**Atomic service API**: This API can be used in atomic services since API version 12. 774 775**System capability**: SystemCapability.ArkUI.ArkUI.Full 776 777| Name | Type | Mandatory| Description | 778| ------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 779| 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.| 780| backgroundColor <sup>12+</sup>| [ResourceColor](arkui-ts/ts-types.md#resourcecolor) | No| Background color of the dialog box.<br>Default value: **Color.Transparent**<br>**NOTE**<br>When **backgroundColor** is set to a non-transparent color, **backgroundBlurStyle** must be set to **BlurStyle.NONE**; otherwise, the color display may not meet the expected effect.| 781| 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.| 782| 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.| 783| 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.| 784| 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.| 785| 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.| 786| 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.| 787| 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| 788| backgroundBlurStyle<sup>12+</sup> | [BlurStyle](arkui-ts/ts-universal-attributes-background.md#blurstyle9) | No | Background blur style of the dialog box.<br>Default value: **BlurStyle.COMPONENT_ULTRA_THICK**<br>**NOTE**<br>Setting this parameter to **BlurStyle.NONE** disables the background blur. When **backgroundBlurStyle** is set to a value other than **NONE**, do not set **backgroundColor**. If you do, the color display may not produce the expected visual effect.| 789 790## BaseDialogOptions<sup>11+</sup> 791 792Defines the options of the dialog box. 793 794**Atomic service API**: This API can be used in atomic services since API version 12. 795 796**System capability**: SystemCapability.ArkUI.ArkUI.Full 797 798| Name | Type | Mandatory| Description | 799| --------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 800| 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**.| 801| 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**.| 802| 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 }**| 803| 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**| 804| showInSubWindow | boolean | No | Whether to show the dialog box in a sub-window.<br>Default value: **false**| 805| 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.| 806| 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**| 807| maskColor<sup>12+</sup> | [ResourceColor](arkui-ts/ts-types.md#resourcecolor) | No | Mask color.<br>Default value: **0x33000000** | 808| 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. | 809| 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.| 810| 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.| 811| 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.| 812| 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**.| 813| keyboardAvoidMode<sup>12+</sup> | [KeyboardAvoidMode](#keyboardavoidmode12) | No| How the dialog box avoids the soft keyboard when it is brought up.<br>Default value: **KeyboardAvoidMode.DEFAULT**<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 814| enableHoverMode<sup>13+</sup> | boolean | No | Whether to enable the hover state.<br>Default value: **false**, meaning not to enable the hover state.| 815| hoverModeArea<sup>13+</sup> | [HoverModeAreaType](arkui-ts/ts-appendix-enums.md#hovermodeareatype13) | No | Display area of the dialog box in the hover state.<br>Default value: **HoverModeAreaType.BOTTOM_SCREEN**| 816 817## DismissDialogAction<sup>12+</sup> 818 819Provides information about the action to dismiss the dialog box. 820 821**Atomic service API**: This API can be used in atomic services since API version 12. 822 823**System capability**: SystemCapability.ArkUI.ArkUI.Full 824 825### Attributes 826 827| Name | Type | Readable| Writable| Description | 828| ------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ | 829| dismiss | Callback<void> | No | No | Callback for dismissing the dialog box. This API is called only when the dialog box needs to be exited.| 830| 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.| 831 832## DismissReason<sup>12+</sup> 833 834**Atomic service API**: This API can be used in atomic services since API version 12. 835 836**System capability**: SystemCapability.ArkUI.ArkUI.Full 837 838| Name | Value | Description | 839| ------------- | ---- | ------------------------------------------------------------ | 840| PRESS_BACK | 0 | Touching the Back button, swiping left or right on the screen, or pressing the Esc key. | 841| TOUCH_OUTSIDE | 1 | Touching the mask. | 842| CLOSE_BUTTON | 2 | Touching the Close button. | 843| SLIDE_DOWN | 3 | Sliding down.<br>**NOTE**<br>This API is effective only in [sheet transition](./arkui-ts/ts-universal-attributes-sheet-transition.md).| 844 845## KeyboardAvoidMode<sup>12+</sup> 846 847**Atomic service API**: This API can be used in atomic services since API version 12. 848 849**System capability**: SystemCapability.ArkUI.ArkUI.Full 850 851| Name | Value | Description | 852| ------- | ---- | ------------------------------------------------ | 853| DEFAULT | 0 | Automatically avoids the soft keyboard and compresses the height when reaching the maximum limit.| 854| NONE | 1 | Does not avoid the soft keyboard. | 855 856## Button 857 858Describes the menu item button in the action menu. 859 860**System capability**: SystemCapability.ArkUI.ArkUI.Full 861 862| Name | Type | Mandatory | Description | 863| ----- | ---------------------------------------- | ---- | ------- | 864| 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.| 865| 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.| 866| 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.| 867