# @ohos.prompt (弹窗) 创建并显示文本æ示框ã€å¯¹è¯æ¡†å’Œæ“作èœå•ã€‚ > **说明:** > 从API Version 9 开始,该接å£ä¸å†ç»´æŠ¤ï¼ŒæŽ¨è使用新接å£[@ohos.promptAction (弹窗)](js-apis-promptAction.md) > > 本模å—首批接å£ä»ŽAPI version 8开始支æŒã€‚åŽç»ç‰ˆæœ¬çš„新增接å£ï¼Œé‡‡ç”¨ä¸Šè§’æ ‡å•ç‹¬æ ‡è®°æŽ¥å£çš„起始版本。 ## å¯¼å…¥æ¨¡å— ```ts import prompt from '@ohos.prompt' ``` ## prompt.showToast showToast(options: ShowToastOptions): void 创建并显示文本æ示框。 **系统能力:** SystemCapability.ArkUI.ArkUI.Full **å‚数:** | å‚æ•°å | 类型 | å¿…å¡« | 说明 | | ------- | ------------------------------------- | ---- | ------- | | options | [ShowToastOptions](#showtoastoptions) | 是 | 文本弹窗选项。 | **示例:** ```ts import prompt from '@ohos.prompt' prompt.showToast({ message: 'Message Info', duration: 2000 }); ```  ## ShowToastOptions 文本æ示框的选项。 **系统能力:** SystemCapability.ArkUI.ArkUI.Full。 | å称 | 类型 | å¿…å¡« | 说明 | | -------- | --------------- | ---- | ------------------------------------------------------------ | | message | string | 是 | 显示的文本信æ¯ã€‚ | | duration | number | å¦ | 默认值1500ms,å–值区间:1500ms-10000ms。若å°äºŽ1500ms则å–默认值,若大于10000ms则å–上é™å€¼10000ms。 | | bottom | string\| number | å¦ | 设置弹窗边框è·ç¦»å±å¹•åº•éƒ¨çš„ä½ç½®ï¼Œæ— 上é™å€¼ï¼Œé»˜è®¤å•ä½vp。 | ## prompt.showDialog showDialog(options: ShowDialogOptions): Promise<ShowDialogSuccessResponse> 创建并显示对è¯æ¡†ï¼Œå¯¹è¯æ¡†å“应åŽåŒæ¥è¿”回结果。 **系统能力:** SystemCapability.ArkUI.ArkUI.Full **å‚数:** | å‚æ•°å | 类型 | å¿…å¡« | 说明 | | ------- | --------------------------------------- | ---- | ------ | | options | [ShowDialogOptions](#showdialogoptions) | 是 | 对è¯æ¡†é€‰é¡¹ã€‚ | **返回值:** | 类型 | 说明 | | ---------------------------------------- | -------- | | Promise<[ShowDialogSuccessResponse](#showdialogsuccessresponse)> | 对è¯æ¡†å“应结果。 | **示例:** ```ts import prompt from '@ohos.prompt' prompt.showDialog({ title: 'Title Info', message: 'Message Info', buttons: [ { text: 'button1', color: '#000000' }, { text: 'button2', color: '#000000' } ], }) .then(data => { console.info('showDialog success, click button: ' + data.index); }) .catch((err:Error) => { console.info('showDialog error: ' + err); }) ```  ## prompt.showDialog showDialog(options: ShowDialogOptions, callback: AsyncCallback<ShowDialogSuccessResponse>):void 创建并显示对è¯æ¡†ï¼Œå¯¹è¯æ¡†å“应结果异æ¥è¿”回。 **系统能力:** SystemCapability.ArkUI.ArkUI.Full **å‚数:** | å‚æ•°å | 类型 | å¿…å¡« | 说明 | | -------- | ---------------------------------------- | ---- | ------------ | | options | [ShowDialogOptions](#showdialogoptions) | 是 | 页é¢æ˜¾ç¤ºå¯¹è¯æ¡†ä¿¡æ¯æ述。 | | callback | AsyncCallback<[ShowDialogSuccessResponse](#showdialogsuccessresponse)> | 是 | 对è¯æ¡†å“应结果回调。 | **示例:** ```ts import prompt from '@ohos.prompt' prompt.showDialog({ title: 'showDialog Title Info', message: 'Message Info', buttons: [ { text: 'button1', color: '#000000' }, { text: 'button2', color: '#000000' } ] }, (err, data) => { if (err) { console.info('showDialog err: ' + err); return; } console.info('showDialog success callback, click button: ' + data.index); }); ```  ## ShowDialogOptions 对è¯æ¡†çš„选项。 **系统能力:** SystemCapability.ArkUI.ArkUI.Full | å称 | 类型 | å¿…å¡« | 说明 | | ------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ | | title | string | å¦ | æ ‡é¢˜æ–‡æœ¬ã€‚ | | message | string | å¦ | 内容文本。 | | buttons | [[Button](#button),[Button](#button)?,[Button](#button)?] | å¦ | 对è¯æ¡†ä¸æŒ‰é’®çš„数组,结构为:{text:'button', color: '\#666666'},支æŒ1-3个按钮。其ä¸ç¬¬ä¸€ä¸ªä¸ºpositiveButton;第二个为negativeButton;第三个为neutralButton。 | ## ShowDialogSuccessResponse 对è¯æ¡†çš„å“应结果。 **系统能力:** SystemCapability.ArkUI.ArkUI.Full | å称 | 类型 | å¿…å¡« | 说明 | | ----- | ------ | ---- | ------------------------------- | | index | number | 是 | 选ä¸æŒ‰é’®åœ¨buttons数组ä¸çš„索引。 | ## prompt.showActionMenu showActionMenu(options: ActionMenuOptions, callback: AsyncCallback<ActionMenuSuccessResponse>):void 创建并显示æ“作èœå•ï¼Œèœå•å“应结果异æ¥è¿”回。 **系统能力:** 以下å„项对应的系统能力å‡ä¸ºSystemCapability.ArkUI.ArkUI.Full。 **å‚数:** | å‚æ•°å | 类型 | å¿…å¡« | 说明 | | -------- | ---------------------------------------- | ---- | --------- | | options | [ActionMenuOptions](#actionmenuoptions) | 是 | æ“作èœå•é€‰é¡¹ã€‚ | | callback | AsyncCallback<[ActionMenuSuccessResponse](#actionmenusuccessresponse)> | 是 | èœå•å“应结果回调。 | **示例:** ```ts import prompt from '@ohos.prompt' prompt.showActionMenu({ title: 'Title Info', buttons: [ { text: 'item1', color: '#666666' }, { text: 'item2', color: '#000000' }, ] }, (err, data) => { if (err) { console.info('showActionMenu err: ' + err); return; } console.info('showActionMenu success callback, click button: ' + data.index); }) ```  ## prompt.showActionMenu showActionMenu(options: ActionMenuOptions): Promise<ActionMenuSuccessResponse> 创建并显示æ“作èœå•ï¼Œèœå•å“应åŽåŒæ¥è¿”回结果。 **系统能力:** SystemCapability.ArkUI.ArkUI.Full **å‚数:** | å‚æ•°å | 类型 | å¿…å¡« | 说明 | | ------- | --------------------------------------- | ---- | ------- | | options | [ActionMenuOptions](#actionmenuoptions) | 是 | æ“作èœå•é€‰é¡¹ã€‚ | **返回值:** | 类型 | 说明 | | ---------------------------------------- | ------- | | Promise<[ActionMenuSuccessResponse](#actionmenusuccessresponse)> | èœå•å“应结果。 | **示例:** ```ts import prompt from '@ohos.prompt' prompt.showActionMenu({ title: 'showActionMenu Title Info', buttons: [ { text: 'item1', color: '#666666' }, { text: 'item2', color: '#000000' }, ] }) .then(data => { console.info('showActionMenu success, click button: ' + data.index); }) .catch((err:Error) => { console.info('showActionMenu error: ' + err); }) ```  ## ActionMenuOptions æ“作èœå•çš„选项。 **系统能力:** SystemCapability.ArkUI.ArkUI.Full。 | å称 | 类型 | å¿…å¡« | 说明 | | ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | title | string | å¦ | æ ‡é¢˜æ–‡æœ¬ã€‚ | | buttons | [[Button](#button),[Button](#button)?,[Button](#button)?,[Button](#button)?,[Button](#button)?,[Button](#button)?] | 是 | èœå•ä¸èœå•é¡¹æŒ‰é’®çš„数组,结构为:{text:'button', color: '\#666666'},支æŒ1-6个按钮。大于6个按钮时弹窗ä¸æ˜¾ç¤ºã€‚ | ## ActionMenuSuccessResponse æ“作èœå•çš„å“应结果。 **系统能力:** SystemCapability.ArkUI.ArkUI.Full | å称 | 类型 | å¿…å¡« | 说明 | | ----- | ------ | ---- | ---------------------------------------- | | index | number | 是 | 选ä¸æŒ‰é’®åœ¨buttons数组ä¸çš„索引,从0开始。 | ## Button èœå•ä¸çš„èœå•é¡¹æŒ‰é’®ã€‚ **系统能力:** SystemCapability.ArkUI.ArkUI.Full | å称 | 类型 | å¿…å¡« | 说明 | | ----- | ------ | ---- | -------------- | | text | string | 是 | 按钮文本内容。 | | color | string | 是 | 按钮文本颜色。 |