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