• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @system.prompt (Prompt)
2
3The **PromptAction** module provides APIs for creating and showing toasts, dialog boxes, and action menus.
4
5> **NOTE**
6>
7> - The APIs of this module are no longer maintained since API version 8. You are advised to use [`@ohos.prompt`](js-apis-prompt.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```js
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```js
37export default {
38  showToast() {
39    prompt.showToast({
40      message: 'Message Info',
41      duration: 2000,
42    });
43  }
44}
45```
46
47
48## prompt.showDialog
49
50showDialog(options: ShowDialogOptions): void
51
52Shows the dialog box.
53
54**System capability**: SystemCapability.ArkUI.ArkUI.Full
55
56**Parameters**
57
58| Name    | Type                                     | Mandatory  | Description         |
59| ------- | --------------------------------------- | ---- | ----------- |
60| options | [ShowDialogOptions](#showdialogoptions) | Yes   | Options for showing the dialog box.|
61
62
63**Example**
64
65```js
66export default {
67  showDialog() {
68    prompt.showDialog({
69      title: 'Title Info',
70      message: 'Message Info',
71      buttons: [
72        {
73           text: 'button',
74           color: '#666666',
75         },
76       ],
77       success: function(data) {
78         console.log('dialog success callback,click button : ' + data.index);
79       },
80       cancel: function() {
81         console.log('dialog cancel callback');
82       },
83     });
84  }
85}
86```
87
88## prompt.showActionMenu<sup>6+</sup>
89
90showActionMenu(options: ShowActionMenuOptions): void
91
92Shows the action menu.
93
94**System capability**: SystemCapability.ArkUI.ArkUI.Full
95
96**Parameters**
97
98| Name    | Type                                      | Mandatory  | Description                  |
99| ------- | ---------------------------------------- | ---- | -------------------- |
100| options | [ShowActionMenuOptions](#showactionmenuoptions) | Yes   | Options for showing the action menu.|
101
102
103**Example**
104
105```js
106export default {
107  showActionMenu() {
108    prompt.showActionMenu({
109      title: 'Title Info',
110      buttons: [
111        {
112          text: 'item1',
113          color: '#666666',
114        },
115        {
116           text: 'item2',
117           color: '#000000',
118        },
119      ],
120      success: function(tapIndex) {
121        console.log('dialog success callback, click button : ' + data.tapIndex);
122      },
123      fail: function(errMsg) {
124        console.log('dialog fail callback' + errMsg);
125      },
126    });
127  }
128}
129```
130## ShowToastOptions
131
132Describes the options for showing the toast.
133
134**System capability**: SystemCapability.ArkUI.ArkUI.Full
135
136| Name                 | Type          | Mandatory  | Description                                      |
137| ------------------- | -------------- | ---- | ---------------------------------------- |
138| message             | string         | Yes   | Text to display.                                |
139| 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.|
140| bottom<sup>5+</sup> | string\|number | No   | Distance between the toast border and the bottom of the screen.                        |
141
142## Button
143
144Defines the prompt information of a button.
145
146**System capability**: SystemCapability.ArkUI.ArkUI.Full
147
148| Name   | Type  | Mandatory  | Description     |
149| ----- | ------ | ---- | ------- |
150| text  | string | Yes   | Text displayed on the button.|
151| color | string | Yes   | Color of the button.|
152
153## ShowDialogSuccessResponse
154
155Defines the dialog box response result.
156
157**System capability**: SystemCapability.ArkUI.ArkUI.Full
158
159| Name   | Type  | Mandatory  | Description        |
160| ----- | ------ | ---- | ---------- |
161| index | number | Yes   | Data index.|
162
163## ShowDialogOptions
164
165Describes the options for showing the dialog box.
166
167**System capability**: SystemCapability.ArkUI.ArkUI.Full
168
169| Name      | Type                                    | Mandatory  | Description                                      |
170| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
171| title    | string                                   | No   | Title of the text to display.                                   |
172| message  | string                                   | No   | Text body.                                   |
173| 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.|
174| success  | (data: [ShowDialogSuccessResponse](#showdialogsuccessresponse)) => void | No   | Callback upon success.                            |
175| cancel   | (data: string, code: string) => void     | No   | Callback upon failure.                            |
176| complete | (data: string) => void                   | No   | Called when the API call is complete.                            |
177
178## ShowActionMenuOptions<sup>6+</sup>
179
180Describes the options for showing the action menu.
181
182**System capability**: SystemCapability.ArkUI.ArkUI.Full
183
184| Name      | Type                                    | Mandatory  | Description                                      |
185| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
186| title    | string                                   | No   | Title of the text to display.                                   |
187| 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.|
188| success  | (tapIndex: number, errMsg: string) => void | No   | Invoked when a dialog box is displayed.                               |
189| fail     | (errMsg: string) => void                 | No   | Callback upon failure.                            |
190| complete | (data: string) => void                   | No   | Invoked when a dialog box is closed.                               |
191