提交 af81a9e6 编写于 作者: W wusongqing

update docs against 6656+6948

Signed-off-by: Nwusongqing <wusongqing@huawei.com>
上级 c3ee93de
# Prompt # Prompt
The **Prompt** module provides APIs for creating and showing toasts, dialog boxes, and action menus.
> **NOTE** > **NOTE**
>
> 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. > 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.
## Modules to Import ## Modules to Import
``` ```js
import prompt from '@ohos.prompt' import prompt from '@ohos.prompt'
``` ```
## Required Permissions
None.
## prompt.showToast ## prompt.showToast
showToast(options: ShowToastOptions): void showToast(options: ShowToastOptions): void
Shows the toast. Shows a toast.
**System capability**: SystemCapability.ArkUI.ArkUI.Full **System capability**: SystemCapability.ArkUI.ArkUI.Full
...@@ -26,15 +26,11 @@ Shows the toast. ...@@ -26,15 +26,11 @@ Shows the toast.
| options | [ShowToastOptions](#showtoastoptions) | Yes | Toast options.| | options | [ShowToastOptions](#showtoastoptions) | Yes | Toast options.|
**Example** **Example**
``` ```js
export default { prompt.showToast({
showToast() { message: 'Message Info',
prompt.showToast({ duration: 2000,
message: 'Message Info', });
duration: 2000,
});
}
}
``` ```
## ShowToastOptions ## ShowToastOptions
...@@ -42,11 +38,11 @@ Describes the options for showing the toast. ...@@ -42,11 +38,11 @@ Describes the options for showing the toast.
**System capability**: SystemCapability.ArkUI.ArkUI.Full **System capability**: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ------ | ---------------------------------------- |
| message | string | Yes | Text to display. | | message | string\| [Resource](.../ui/ts-types.md#resource-type)<sup>9+</sup>| Yes | Text to display. |
| 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.| | 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.|
| bottom | &lt;length&gt; | No | Distance between the toast border and the bottom of the screen. | | bottom | string\| number | No | Distance between the toast border and the bottom of the screen. |
## prompt.showDialog ## prompt.showDialog
...@@ -69,38 +65,34 @@ Shows a dialog box. This API uses a promise to return the result synchronously. ...@@ -69,38 +65,34 @@ Shows a dialog box. This API uses a promise to return the result synchronously.
**Example** **Example**
``` ```js
export default { prompt.showDialog({
showDialog() { title: 'Title Info',
prompt.showDialog({ message: 'Message Info',
title: 'Title Info', buttons: [
message: 'Message Info', {
buttons: [ text: 'button1',
{ color: '#000000',
text: 'button1', },
color: '#000000', {
}, text: 'button2',
{ color: '#000000',
text: 'button2',
color: '#000000',
}
],
})
.then(data => {
console.info('showDialog success, click button: ' + data.index);
})
.catch(err => {
console.info('showDialog error: ' + err);
})
} }
} ],
})
.then(data => {
console.info('showDialog success, click button: ' + data.index);
})
.catch(err => {
console.info('showDialog error: ' + err);
})
``` ```
## prompt.showDialog ## prompt.showDialog
showDialog(options: ShowDialogOptions, callback: AsyncCallback&lt;ShowDialogSuccessResponse&gt;):void showDialog(options: ShowDialogOptions, callback: AsyncCallback&lt;ShowDialogSuccessResponse&gt;):void
Shows a dialog box. This API uses a callback to return the result asynchronously. Shows a dialog box. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.ArkUI.ArkUI.Full **System capability**: SystemCapability.ArkUI.ArkUI.Full
...@@ -112,32 +104,27 @@ Shows a dialog box. This API uses a callback to return the result asynchronously ...@@ -112,32 +104,27 @@ Shows a dialog box. This API uses a callback to return the result asynchronously
| callback | AsyncCallback&lt;[ShowDialogSuccessResponse](#showdialogsuccessresponse)&gt; | Yes | Callback used to return the dialog box response result. | | callback | AsyncCallback&lt;[ShowDialogSuccessResponse](#showdialogsuccessresponse)&gt; | Yes | Callback used to return the dialog box response result. |
**Example** **Example**
``` ```js
export default { prompt.showDialog({
callback(err, data) { title: 'showDialog Title Info',
if(err) { message: 'Message Info',
console.info('showDialog err: ' + err); buttons: [
return; {
} text: 'button1',
console.info('showDialog success callback, click button: ' + data.index); color: '#000000',
}, },
showDialog() { {
prompt.showDialog({ text: 'button2',
title: 'showDialog Title Info', color: '#000000',
message: 'Message Info',
buttons: [
{
text: 'button1',
color: '#000000',
},
{
text: 'button2',
color: '#000000',
}
]
}, this.callback);
} }
]
}, (err, data) => {
if (err) {
console.info('showDialog err: ' + err);
return;
} }
console.info('showDialog success callback, click button: ' + data.index);
});
``` ```
## ShowDialogOptions ## ShowDialogOptions
...@@ -146,11 +133,11 @@ Describes the options for showing the dialog box. ...@@ -146,11 +133,11 @@ Describes the options for showing the dialog box.
**System capability**: SystemCapability.ArkUI.ArkUI.Full **System capability**: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------ | ---- | ---------------------------------------- | | ------- | ---------------------------------------- | ---- | ---------------------------------------- |
| title | string | No | Title of the text to display. | | title | string\| [Resource](.../ui/ts-types.md#resource-type)<sup>9+</sup>| No | Title of the dialog box. |
| message | string | No | Text body. | | message | string\| [Resource](.../ui/ts-types.md#resource-type)<sup>9+</sup>| No | Text body. |
| buttons | Array | No | Array of buttons in the dialog box. The array structure is **{text:'button',&nbsp;color:&nbsp;'\#666666'}**. One 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.| | buttons | Array | 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.|
## ShowDialogSuccessResponse ## ShowDialogSuccessResponse
...@@ -160,7 +147,7 @@ Describes the dialog box response result. ...@@ -160,7 +147,7 @@ Describes the dialog box response result.
| Name | Type | Description | | Name | Type | Description |
| ----- | ------ | ------------------- | | ----- | ------ | ------------------- |
| index | number | Index of the selected button in the array.| | index | number | Index of the selected button in the **buttons** array.|
## prompt.showActionMenu ## prompt.showActionMenu
...@@ -179,36 +166,31 @@ Shows an action menu. This API uses a callback to return the result asynchronous ...@@ -179,36 +166,31 @@ Shows an action menu. This API uses a callback to return the result asynchronous
**Example** **Example**
``` ```js
export default { prompt.showActionMenu({
callback(err, data) { title: 'Title Info',
if(err) { buttons: [
console.info('showActionMenu err: ' + err); {
return; text: 'item1',
} color: '#666666',
console.info('showActionMenu success callback, click button: ' + data.index);
}, },
showActionMenu() { {
prompt.showActionMenu({ text: 'item2',
title: 'Title Info', color: '#000000',
buttons: [ },
{ ]
text: 'item1', }, (err, data) => {
color: '#666666', if (err) {
}, console.info('showActionMenu err: ' + err);
{ return;
text: 'item2',
color: '#000000',
},
]
}, this.callback)
}
} }
console.info('showActionMenu success callback, click button: ' + data.index);
})
``` ```
## prompt.showActionMenu ## prompt.showActionMenu
showActionMenu(options: ActionMenuOptions): Promise\<ActionMenuSuccessResponse> showActionMenu(options: ActionMenuOptions): Promise&lt;ActionMenuSuccessResponse&gt;
Shows an action menu. This API uses a promise to return the result synchronously. Shows an action menu. This API uses a promise to return the result synchronously.
...@@ -225,30 +207,26 @@ Shows an action menu. This API uses a promise to return the result synchronously ...@@ -225,30 +207,26 @@ Shows an action menu. This API uses a promise to return the result synchronously
| Promise&lt;[ActionMenuSuccessResponse](#actionmenusuccessresponse)&gt; | Promise used to return the action menu response result.| | Promise&lt;[ActionMenuSuccessResponse](#actionmenusuccessresponse)&gt; | Promise used to return the action menu response result.|
**Example** **Example**
``` ```js
export default { prompt.showActionMenu({
showActionMenu() { title: 'showActionMenu Title Info',
prompt.showActionMenu({ buttons: [
title: 'showActionMenu Title Info', {
buttons: [ text: 'item1',
{ color: '#666666',
text: 'item1', },
color: '#666666', {
}, text: 'item2',
{ color: '#000000',
text: 'item2', },
color: '#000000', ]
}, })
] .then(data => {
}) console.info('showActionMenu success, click button: ' + data.index);
.then(data => { })
console.info('showActionMenu success, click button: ' + data.index); .catch(err => {
}) console.info('showActionMenu error: ' + err);
.catch(err => { })
console.info('showActionMenu error: ' + err);
})
}
}
``` ```
## ActionMenuOptions ## ActionMenuOptions
...@@ -256,10 +234,10 @@ Describes the options for showing the action menu. ...@@ -256,10 +234,10 @@ Describes the options for showing the action menu.
**System capability**: SystemCapability.ArkUI.ArkUI.Full **System capability**: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------ | ---- | ---------------------------------------- | | ------- | ---------------------------------------- | ---- | ---------------------------------------- |
| title | string | No | Title of the text to display. | | title | string\| [Resource](.../ui/ts-types.md#resource-type)<sup>9+</sup>| No | Title of the text to display. |
| buttons | Array | Yes | Array of menu items. The array structure is **{text:'button',&nbsp;color:&nbsp;'\#666666'}**. One to six items are supported. If there are more than six items, extra items will not be displayed.| | buttons | Array&lt;[Button](#button)&gt; | 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.|
## ActionMenuSuccessResponse ## ActionMenuSuccessResponse
...@@ -269,4 +247,15 @@ Describes the action menu response result. ...@@ -269,4 +247,15 @@ Describes the action menu response result.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ----- | ------ | ---- | ------------------------ | | ----- | ------ | ---- | ------------------------ |
| index | number | No | Index of the selected button in the array, starting from **0**.| | index | number | No | Index of the selected button in the **buttons** array, starting from **0**.|
## Button
Describes the menu item button in the action menu.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Mandatory | Description |
| ----- | ---------------------------------------- | ---- | ------- |
| text | string\| [Resource](.../ui/ts-types.md#resource-type)<sup>9+</sup>| Yes | Button text.|
| color | string\| [Resource](.../ui/ts-types.md#resource-type)<sup>9+</sup>| Yes | Text color of the button.|
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册