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