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