1# @system.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 8. You are advised to use [@ohos.promptAction](js-apis-promptAction.md) instead. 8> 9> 10> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version. 11 12 13## Modules to Import 14 15 16```ts 17import prompt from '@system.prompt'; 18``` 19 20## prompt.showToast 21 22showToast(options: ShowToastOptions): void 23 24Shows the toast. 25 26**System capability**: SystemCapability.ArkUI.ArkUI.Full 27 28**Parameters** 29 30| Name | Type | Mandatory | Description | 31| ------- | ------------------------------------- | ---- | --------------- | 32| options | [ShowToastOptions](#showtoastoptions) | Yes | Options for showing the toast.| 33 34**Example** 35 36```ts 37import prompt from '@system.prompt'; 38class A{ 39 showToast() { 40 prompt.showToast({ 41 message: 'Message Info', 42 duration: 2000 43 }); 44 } 45} 46export default new A() 47``` 48 49 50## prompt.showDialog 51 52showDialog(options: ShowDialogOptions): void 53 54Shows the dialog box. 55 56**System capability**: SystemCapability.ArkUI.ArkUI.Full 57 58**Parameters** 59 60| Name | Type | Mandatory | Description | 61| ------- | --------------------------------------- | ---- | ----------- | 62| options | [ShowDialogOptions](#showdialogoptions) | Yes | Options for showing the dialog box.| 63 64 65**Example** 66 67```ts 68import prompt from '@system.prompt'; 69class B{ 70 showDialog() { 71 prompt.showDialog({ 72 title: 'Title Info', 73 message: 'Message Info', 74 buttons: [ 75 { 76 text: 'button', 77 color: '#666666' 78 }, 79 ], 80 success: (data)=> { 81 console.log('dialog success callback, click button : ' + data.index); 82 }, 83 cancel: ()=> { 84 console.log('dialog cancel callback'); 85 }, 86 }); 87 } 88} 89export default new B() 90``` 91 92## prompt.showActionMenu<sup>6+</sup> 93 94showActionMenu(options: ShowActionMenuOptions): void 95 96Shows the action menu. 97 98**System capability**: SystemCapability.ArkUI.ArkUI.Full 99 100**Parameters** 101 102| Name | Type | Mandatory | Description | 103| ------- | ---------------------------------------- | ---- | -------------------- | 104| options | [ShowActionMenuOptions](#showactionmenuoptions6) | Yes | Options for showing the action menu.| 105 106 107**Example** 108 109```ts 110import prompt from '@system.prompt'; 111class C{ 112 showActionMenu() { 113 prompt.showActionMenu({ 114 title: 'Title Info', 115 buttons: [ 116 { 117 text: 'item1', 118 color: '#666666' 119 }, 120 { 121 text: 'item2', 122 color: '#000000' 123 }, 124 ], 125 success: (tapIndex)=> { 126 console.log('dialog success callback, click button : ' + data.tapIndex); 127 }, 128 fail: (errMsg)=> { 129 console.log('dialog fail callback' + errMsg); 130 }, 131 }); 132 } 133} 134export default new C() 135``` 136## ShowToastOptions 137 138Describes the options for showing the toast. 139 140**System capability**: SystemCapability.ArkUI.ArkUI.Full 141 142| Name | Type | Mandatory | Description | 143| ------------------- | -------------- | ---- | ---------------------------------------- | 144| message | string | Yes | Text to display. | 145| duration | number | No | Duration that the toast will remain on the screen. The default value is 1500 ms. The recommended value range is 1500 ms to 10000 ms. If a value less than 1500 ms is set, the default value is used.| 146| bottom<sup>5+</sup> | string\|number | No | Distance between the toast border and the bottom of the screen. | 147 148## Button 149 150Defines the prompt information of a button. 151 152**System capability**: SystemCapability.ArkUI.ArkUI.Full 153 154| Name | Type | Mandatory | Description | 155| ----- | ------ | ---- | ------- | 156| text | string | Yes | Text displayed on the button.| 157| color | string | Yes | Color of the button.| 158 159## ShowDialogSuccessResponse 160 161Defines the dialog box response result. 162 163**System capability**: SystemCapability.ArkUI.ArkUI.Full 164 165| Name | Type | Mandatory | Description | 166| ----- | ------ | ---- | ---------- | 167| index | number | Yes | Data index.| 168 169## ShowDialogOptions 170 171Describes the options for showing the dialog box. 172 173**System capability**: SystemCapability.ArkUI.ArkUI.Full 174 175| Name | Type | Mandatory | Description | 176| -------- | ---------------------------------------- | ---- | ---------------------------------------- | 177| title | string | No | Title of the text to display. | 178| message | string | No | Text body. | 179| buttons | [[Button](#button), [Button](#button)?, [Button](#button)?] | No | Array of buttons in the dialog box. The array structure is **{text:'button', color: '\#666666'}**. One to six buttons are supported. If there are more than six buttons, extra buttons will not be displayed.| 180| success | (data: [ShowDialogSuccessResponse](#showdialogsuccessresponse)) => void | No | Callback upon success. | 181| cancel | (data: string, code: string) => void | No | Callback upon failure. | 182| complete | (data: string) => void | No | Called when the API call is complete. | 183 184## ShowActionMenuOptions<sup>6+</sup> 185 186Describes the options for showing the action menu. 187 188**System capability**: SystemCapability.ArkUI.ArkUI.Full 189 190| Name | Type | Mandatory | Description | 191| -------- | ---------------------------------------- | ---- | ---------------------------------------- | 192| title | string | No | Title of the text to display. | 193| buttons | [[Button](#button), [Button](#button)?, [Button](#button)?, [Button](#button)?, [Button](#button)?, [Button](#button)?] | Yes | Array of buttons in the dialog box. The array structure is **{text:'button', color: '\#666666'}**. One to six buttons are supported.| 194| success | (tapIndex: number, errMsg: string) => void | No | Invoked when a dialog box is displayed. | 195| fail | (errMsg: string) => void | No | Callback upon failure. | 196| complete | (data: string) => void | No | Invoked when a dialog box is closed. | 197