W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
創(chuàng)建并顯示文本提示框、對話框和操作菜單。
本模塊首批接口從API version 9開始支持。后續(xù)版本的新增接口,采用上角標單獨標記接口的起始版本。
該模塊不支持在UIAbility的文件聲明處使用,即不能在UIAbility的生命周期中調(diào)用,需要在創(chuàng)建組件實例后使用。
showToast(options: ShowToastOptions): void
創(chuàng)建并顯示文本提示框。
系統(tǒng)能力: SystemCapability.ArkUI.ArkUI.Full
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
options | 是 | 文本彈窗選項。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見ohos.promptAction(彈窗)錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
100001 | if UI execution context not found. |
示例:
- try {
- promptAction.showToast({
- message: 'Message Info',
- duration: 2000,
- });
- } catch (error) {
- console.error(`showToast args error code is ${error.code}, message is ${error.message}`);
- };
文本提示框的選項。
系統(tǒng)能力: SystemCapability.ArkUI.ArkUI.Full。
名稱 | 類型 | 必填 | 說明 |
---|---|---|---|
message | string| Resource9+ | 是 | 顯示的文本信息。默認字體為'Harmony Sans',不支持設(shè)置其他字體。 |
duration | number | 否 | 默認值1500ms,取值區(qū)間:1500ms-10000ms。若小于1500ms則取默認值,若大于10000ms則取上限值10000ms。 |
bottom | string| number | 否 | 設(shè)置彈窗邊框距離屏幕底部的位置。 |
showDialog(options: ShowDialogOptions): Promise<ShowDialogSuccessResponse>
創(chuàng)建并顯示對話框,對話框響應后同步返回結(jié)果。
系統(tǒng)能力: SystemCapability.ArkUI.ArkUI.Full
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
options | 是 | 對話框選項。 |
返回值:
類型 | 說明 |
---|---|
Promise<ShowDialogSuccessResponse> | 對話框響應結(jié)果。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見ohos.promptAction(彈窗)錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
100001 | if UI execution context not found. |
示例:
- try {
- promptAction.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 => {
- console.info('showDialog error: ' + err);
- })
- } catch (error) {
- console.error(`showDialog args error code is ${error.code}, message is ${error.message}`);
- };
showDialog(options: ShowDialogOptions, callback: AsyncCallback<ShowDialogSuccessResponse>):void
創(chuàng)建并顯示對話框,對話框響應結(jié)果異步返回。
系統(tǒng)能力: SystemCapability.ArkUI.ArkUI.Full
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
options | 是 | 頁面顯示對話框信息描述。 | |
callback | AsyncCallback<ShowDialogSuccessResponse> | 是 | 對話框響應結(jié)果回調(diào)。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見ohos.promptAction(彈窗)錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
100001 | if UI execution context not found. |
示例:
- try {
- promptAction.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);
- });
- } catch (error) {
- console.error(`showDialog args error code is ${error.code}, message is ${error.message}`);
- };
對話框的響應結(jié)果。
系統(tǒng)能力: SystemCapability.ArkUI.ArkUI.Full
名稱 | 類型 | 必填 | 說明 |
---|---|---|---|
index | number | 否 | 選中按鈕在buttons數(shù)組中的索引。 |
showActionMenu(options: ActionMenuOptions, callback: AsyncCallback<ActionMenuSuccessResponse>):void
創(chuàng)建并顯示操作菜單,菜單響應結(jié)果異步返回。
系統(tǒng)能力: SystemCapability.ArkUI.ArkUI.Full。
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
options | 是 | 操作菜單選項。 | |
callback | AsyncCallback<ActionMenuSuccessResponse> | 是 | 菜單響應結(jié)果回調(diào)。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見ohos.promptAction(彈窗)錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
100001 | if UI execution context not found. |
示例:
- try {
- promptAction.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);
- })
- } catch (error) {
- console.error(`showActionMenu args error code is ${error.code}, message is ${error.message}`);
- };
showActionMenu(options: ActionMenuOptions): Promise<ActionMenuSuccessResponse>
創(chuàng)建并顯示操作菜單,菜單響應后同步返回結(jié)果。
系統(tǒng)能力: SystemCapability.ArkUI.ArkUI.Full
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
options | 是 | 操作菜單選項。 |
返回值:
類型 | 說明 |
---|---|
Promise<ActionMenuSuccessResponse> | 菜單響應結(jié)果。 |
錯誤碼:
以下錯誤碼的詳細介紹請參見ohos.promptAction(彈窗)錯誤碼。
錯誤碼ID | 錯誤信息 |
---|---|
100001 | if UI execution context not found. |
示例:
- try {
- promptAction.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 => {
- console.info('showActionMenu error: ' + err);
- })
- } catch (error) {
- console.error(`showActionMenu args error code is ${error.code}, message is ${error.message}`);
- };
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: