1e41f4b71Sopenharmony_ci# @ohos.prompt (Prompt) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **Prompt** module provides APIs for creating and showing toasts, dialog boxes, and action menus. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> The APIs of this module are deprecated since API Version 9. You are advised to use [@ohos.promptAction](js-apis-promptAction.md) instead. 7e41f4b71Sopenharmony_ci> 8e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## Modules to Import 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci```ts 13e41f4b71Sopenharmony_ciimport prompt from '@ohos.prompt' 14e41f4b71Sopenharmony_ci``` 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci## prompt.showToast 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_cishowToast(options: ShowToastOptions): void 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ciShows a toast. 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci**Parameters** 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 27e41f4b71Sopenharmony_ci| ------- | ------------------------------------- | ---- | ------- | 28e41f4b71Sopenharmony_ci| options | [ShowToastOptions](#showtoastoptions) | Yes | Toast options. | 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci**Example** 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci```ts 33e41f4b71Sopenharmony_ciimport prompt from '@ohos.prompt' 34e41f4b71Sopenharmony_ciprompt.showToast({ 35e41f4b71Sopenharmony_ci message: 'Message Info', 36e41f4b71Sopenharmony_ci duration: 2000 37e41f4b71Sopenharmony_ci}); 38e41f4b71Sopenharmony_ci``` 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci## ShowToastOptions 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ciDescribes the options for showing the toast. 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 49e41f4b71Sopenharmony_ci| -------- | --------------- | ---- | ------------------------------------------------------------ | 50e41f4b71Sopenharmony_ci| message | string | Yes | Text to display. | 51e41f4b71Sopenharmony_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. | 52e41f4b71Sopenharmony_ci| bottom | string\| number | No | Distance between the toast border and the bottom of the screen. It does not have an upper limit. The default unit is vp. | 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci## prompt.showDialog 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_cishowDialog(options: ShowDialogOptions): Promise<ShowDialogSuccessResponse> 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ciShows a dialog box. This API uses a promise to return the result synchronously. 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ci**Parameters** 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 65e41f4b71Sopenharmony_ci| ------- | --------------------------------------- | ---- | ------ | 66e41f4b71Sopenharmony_ci| options | [ShowDialogOptions](#showdialogoptions) | Yes | Dialog box options. | 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci**Return value** 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci| Type | Description | 71e41f4b71Sopenharmony_ci| ---------------------------------------- | -------- | 72e41f4b71Sopenharmony_ci| Promise<[ShowDialogSuccessResponse](#showdialogsuccessresponse)> | Promise used to return the dialog box response result. | 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci**Example** 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci```ts 77e41f4b71Sopenharmony_ciimport prompt from '@ohos.prompt' 78e41f4b71Sopenharmony_ciprompt.showDialog({ 79e41f4b71Sopenharmony_ci title: 'Title Info', 80e41f4b71Sopenharmony_ci message: 'Message Info', 81e41f4b71Sopenharmony_ci buttons: [ 82e41f4b71Sopenharmony_ci { 83e41f4b71Sopenharmony_ci text: 'button1', 84e41f4b71Sopenharmony_ci color: '#000000' 85e41f4b71Sopenharmony_ci }, 86e41f4b71Sopenharmony_ci { 87e41f4b71Sopenharmony_ci text: 'button2', 88e41f4b71Sopenharmony_ci color: '#000000' 89e41f4b71Sopenharmony_ci } 90e41f4b71Sopenharmony_ci ], 91e41f4b71Sopenharmony_ci}) 92e41f4b71Sopenharmony_ci .then(data => { 93e41f4b71Sopenharmony_ci console.info('showDialog success, click button: ' + data.index); 94e41f4b71Sopenharmony_ci }) 95e41f4b71Sopenharmony_ci .catch((err:Error) => { 96e41f4b71Sopenharmony_ci console.info('showDialog error: ' + err); 97e41f4b71Sopenharmony_ci }) 98e41f4b71Sopenharmony_ci``` 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci## prompt.showDialog 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_cishowDialog(options: ShowDialogOptions, callback: AsyncCallback<ShowDialogSuccessResponse>):void 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ciShows a dialog box. This API uses an asynchronous callback to return the result. 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci**Parameters** 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 113e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------ | 114e41f4b71Sopenharmony_ci| options | [ShowDialogOptions](#showdialogoptions) | Yes | Dialog box options. | 115e41f4b71Sopenharmony_ci| callback | AsyncCallback<[ShowDialogSuccessResponse](#showdialogsuccessresponse)> | Yes | Callback used to return the dialog box response result. | 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ci**Example** 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci```ts 120e41f4b71Sopenharmony_ciimport prompt from '@ohos.prompt' 121e41f4b71Sopenharmony_ciprompt.showDialog({ 122e41f4b71Sopenharmony_ci title: 'showDialog Title Info', 123e41f4b71Sopenharmony_ci message: 'Message Info', 124e41f4b71Sopenharmony_ci buttons: [ 125e41f4b71Sopenharmony_ci { 126e41f4b71Sopenharmony_ci text: 'button1', 127e41f4b71Sopenharmony_ci color: '#000000' 128e41f4b71Sopenharmony_ci }, 129e41f4b71Sopenharmony_ci { 130e41f4b71Sopenharmony_ci text: 'button2', 131e41f4b71Sopenharmony_ci color: '#000000' 132e41f4b71Sopenharmony_ci } 133e41f4b71Sopenharmony_ci ] 134e41f4b71Sopenharmony_ci}, (err, data) => { 135e41f4b71Sopenharmony_ci if (err) { 136e41f4b71Sopenharmony_ci console.info('showDialog err: ' + err); 137e41f4b71Sopenharmony_ci return; 138e41f4b71Sopenharmony_ci } 139e41f4b71Sopenharmony_ci console.info('showDialog success callback, click button: ' + data.index); 140e41f4b71Sopenharmony_ci}); 141e41f4b71Sopenharmony_ci``` 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ci## ShowDialogOptions 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ciDescribes the options for showing the dialog box. 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 152e41f4b71Sopenharmony_ci| ------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ | 153e41f4b71Sopenharmony_ci| title | string | No | Title of the dialog box. | 154e41f4b71Sopenharmony_ci| message | string | No | Text body. | 155e41f4b71Sopenharmony_ci| buttons | [[Button](#button),[Button](#button)?,[Button](#button)?] | No | Array of buttons in the dialog box. The array structure is **{text:'button', color: '\#666666'}**. Up to three buttons are supported. The first button is of the **positiveButton** type, the second is of the **negativeButton** type, and the third is of the **neutralButton** type. | 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci## ShowDialogSuccessResponse 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ciDescribes the dialog box response result. 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 164e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ------------------------------- | 165e41f4b71Sopenharmony_ci| index | number | Yes | Index of the selected button in the **buttons** array. | 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci## prompt.showActionMenu 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_cishowActionMenu(options: ActionMenuOptions, callback: AsyncCallback<ActionMenuSuccessResponse>):void 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ciShows an action menu. This API uses a callback to return the result asynchronously. 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci**Parameters** 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 179e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | --------- | 180e41f4b71Sopenharmony_ci| options | [ActionMenuOptions](#actionmenuoptions) | Yes | Action menu options. | 181e41f4b71Sopenharmony_ci| callback | AsyncCallback<[ActionMenuSuccessResponse](#actionmenusuccessresponse)> | Yes | Callback used to return the action menu response result. | 182e41f4b71Sopenharmony_ci 183e41f4b71Sopenharmony_ci**Example** 184e41f4b71Sopenharmony_ci 185e41f4b71Sopenharmony_ci```ts 186e41f4b71Sopenharmony_ciimport prompt from '@ohos.prompt' 187e41f4b71Sopenharmony_ciprompt.showActionMenu({ 188e41f4b71Sopenharmony_ci title: 'Title Info', 189e41f4b71Sopenharmony_ci buttons: [ 190e41f4b71Sopenharmony_ci { 191e41f4b71Sopenharmony_ci text: 'item1', 192e41f4b71Sopenharmony_ci color: '#666666' 193e41f4b71Sopenharmony_ci }, 194e41f4b71Sopenharmony_ci { 195e41f4b71Sopenharmony_ci text: 'item2', 196e41f4b71Sopenharmony_ci color: '#000000' 197e41f4b71Sopenharmony_ci }, 198e41f4b71Sopenharmony_ci ] 199e41f4b71Sopenharmony_ci}, (err, data) => { 200e41f4b71Sopenharmony_ci if (err) { 201e41f4b71Sopenharmony_ci console.info('showActionMenu err: ' + err); 202e41f4b71Sopenharmony_ci return; 203e41f4b71Sopenharmony_ci } 204e41f4b71Sopenharmony_ci console.info('showActionMenu success callback, click button: ' + data.index); 205e41f4b71Sopenharmony_ci}) 206e41f4b71Sopenharmony_ci``` 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ci 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ci## prompt.showActionMenu 211e41f4b71Sopenharmony_ci 212e41f4b71Sopenharmony_cishowActionMenu(options: ActionMenuOptions): Promise<ActionMenuSuccessResponse> 213e41f4b71Sopenharmony_ci 214e41f4b71Sopenharmony_ciShows an action menu. This API uses a promise to return the result synchronously. 215e41f4b71Sopenharmony_ci 216e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 217e41f4b71Sopenharmony_ci 218e41f4b71Sopenharmony_ci**Parameters** 219e41f4b71Sopenharmony_ci 220e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 221e41f4b71Sopenharmony_ci| ------- | --------------------------------------- | ---- | ------- | 222e41f4b71Sopenharmony_ci| options | [ActionMenuOptions](#actionmenuoptions) | Yes | Action menu options. | 223e41f4b71Sopenharmony_ci 224e41f4b71Sopenharmony_ci**Return value** 225e41f4b71Sopenharmony_ci 226e41f4b71Sopenharmony_ci| Type | Description | 227e41f4b71Sopenharmony_ci| ---------------------------------------- | ------- | 228e41f4b71Sopenharmony_ci| Promise<[ActionMenuSuccessResponse](#actionmenusuccessresponse)> | Promise used to return the action menu response result. | 229e41f4b71Sopenharmony_ci 230e41f4b71Sopenharmony_ci**Example** 231e41f4b71Sopenharmony_ci 232e41f4b71Sopenharmony_ci```ts 233e41f4b71Sopenharmony_ciimport prompt from '@ohos.prompt' 234e41f4b71Sopenharmony_ciprompt.showActionMenu({ 235e41f4b71Sopenharmony_ci title: 'showActionMenu Title Info', 236e41f4b71Sopenharmony_ci buttons: [ 237e41f4b71Sopenharmony_ci { 238e41f4b71Sopenharmony_ci text: 'item1', 239e41f4b71Sopenharmony_ci color: '#666666' 240e41f4b71Sopenharmony_ci }, 241e41f4b71Sopenharmony_ci { 242e41f4b71Sopenharmony_ci text: 'item2', 243e41f4b71Sopenharmony_ci color: '#000000' 244e41f4b71Sopenharmony_ci }, 245e41f4b71Sopenharmony_ci ] 246e41f4b71Sopenharmony_ci}) 247e41f4b71Sopenharmony_ci .then(data => { 248e41f4b71Sopenharmony_ci console.info('showActionMenu success, click button: ' + data.index); 249e41f4b71Sopenharmony_ci }) 250e41f4b71Sopenharmony_ci .catch((err:Error) => { 251e41f4b71Sopenharmony_ci console.info('showActionMenu error: ' + err); 252e41f4b71Sopenharmony_ci }) 253e41f4b71Sopenharmony_ci``` 254e41f4b71Sopenharmony_ci 255e41f4b71Sopenharmony_ci 256e41f4b71Sopenharmony_ci## ActionMenuOptions 257e41f4b71Sopenharmony_ci 258e41f4b71Sopenharmony_ciDescribes the options for showing the action menu. 259e41f4b71Sopenharmony_ci 260e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 261e41f4b71Sopenharmony_ci 262e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 263e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 264e41f4b71Sopenharmony_ci| title | string | No | Title of the text to display. | 265e41f4b71Sopenharmony_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, extra buttons will not be displayed. | 266e41f4b71Sopenharmony_ci 267e41f4b71Sopenharmony_ci## ActionMenuSuccessResponse 268e41f4b71Sopenharmony_ci 269e41f4b71Sopenharmony_ciDescribes the action menu response result. 270e41f4b71Sopenharmony_ci 271e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 272e41f4b71Sopenharmony_ci 273e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 274e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ---------------------------------------- | 275e41f4b71Sopenharmony_ci| index | number | Yes | Index of the selected button in the **buttons** array, starting from **0**. | 276e41f4b71Sopenharmony_ci 277e41f4b71Sopenharmony_ci## Button 278e41f4b71Sopenharmony_ci 279e41f4b71Sopenharmony_ciDescribes the menu item button in the action menu. 280e41f4b71Sopenharmony_ci 281e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 282e41f4b71Sopenharmony_ci 283e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 284e41f4b71Sopenharmony_ci| ----- | ------ | ---- | -------------- | 285e41f4b71Sopenharmony_ci| text | string | Yes | Button text. | 286e41f4b71Sopenharmony_ci| color | string | Yes | Text color of the button. | 287