鸿蒙语言基础类库:【@system.prompt (弹窗)】

弹窗

说明:

  • 从API Version 8 开始,该接口不再维护,推荐使用新接口`@ohos.prompt`。
  • 本模块首批接口从API version 3开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

导入模块

复制代码
import prompt from '@system.prompt';

prompt.showToast

showToast(options: ShowToastOptions): void

显示文本弹窗。

系统能力: SystemCapability.ArkUI.ArkUI.Full

参数:

参数名 类型 必填 说明
options ShowToastOptions 是 定义ShowToast的选项。

示例:

复制代码
export default {    
  showToast() {        
    prompt.showToast({            
      message: 'Message Info',            
      duration: 2000,        
    });    
  }
}

prompt.showDialog

showDialog(options: ShowDialogOptions): void

显示对话框。

系统能力: SystemCapability.ArkUI.ArkUI.Full

参数:

参数名 类型 必填 说明
options ShowDialogOptions 是 定义显示对话框的选项。

示例:

复制代码
export default {    
  showDialog() {       
    prompt.showDialog({           
      title: 'Title Info',            
      message: 'Message Info',           
      buttons: [                
        {                    
           text: 'button',                   
           color: '#666666',                
         },            
       ],            
       success: function(data) {                
         console.log('dialog success callback,click button : ' + data.index);            
       },            
       cancel: function() {                
         console.log('dialog cancel callback');            
       },
     });    
  }
}

prompt.showActionMenu6+

showActionMenu(options: ShowActionMenuOptions): void

显示操作菜单。

系统能力: SystemCapability.ArkUI.ArkUI.Full

参数:

参数名 类型 必填 说明
options ShowActionMenuOptions 是 定义ShowActionMenu的选项。

示例:

复制代码
export default {    
  showActionMenu() {        
    prompt.showActionMenu({            
      title: 'Title Info',            
      buttons: [                
        {                    
          text: 'item1',                    
          color: '#666666',                
        },                
        {                    
           text: 'item2',                    
           color: '#000000',                
        },            
      ],            
      success: function(tapIndex) {                
        console.log('dialog success callback,click button : ' + tapIndex);            
      },            
      fail: function(errMsg) {                
        console.log('dialog fail callback' + errMsg);            
      },       
    });    
  }
}

ShowToastOptions

定义ShowToast的选项。

系统能力: 以下各项对应的系统能力均为SystemCapability.ArkUI.ArkUI.Full

名称 参数类型 必填 说明
message string 是 显示的文本信息。
duration number 否 默认值1500ms,建议区间:1500ms-10000ms。若小于1500ms则取默认值,最大取值为10000ms。
bottom5+ string number 否

Button

定义按钮的提示信息。

系统能力: 以下各项对应的系统能力均为SystemCapability.ArkUI.ArkUI.Full

名称 参数类型 必填 说明
text string 是 定义按钮信息。
color string 是 定义按钮颜色。

ShowDialogSuccessResponse

定义ShowDialog的响应。

系统能力: 以下各项对应的系统能力均为SystemCapability.ArkUI.ArkUI.Full

名称 参数类型 必填 说明
index number 是 定义数据的索引信息。

ShowDialogOptions

定义显示对话框的选项。

系统能力: 以下各项对应的系统能力均为SystemCapability.ArkUI.ArkUI.Full

名称 参数类型 必填 说明
title string 否 标题文本。
message string 否 文本内容。
buttons [Button](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.2-Beta1/zh-cn/application-dev/reference/apis/js-apis-system-prompt.md#button), [Button](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.2-Beta1/zh-cn/application-dev/reference/apis/js-apis-system-prompt.md#button)?, [Button](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.2-Beta1/zh-cn/application-dev/reference/apis/js-apis-system-prompt.md#button)? 否 对话框中按钮的数组,结构为:{text:'button', color: '#666666'},支持1-6个按钮。大于6个按钮时弹窗不显示。
success (data: ShowDialogSuccessResponse) => void 否 接口调用成功的回调函数。
cancel (data: string, code: string) => void 否 接口调用失败的回调函数。
complete (data: string) => void 否 接口调用结束的回调函数。

ShowActionMenuOptions6+

定义ShowActionMenu的选项。

系统能力: 以下各项对应的系统能力均为SystemCapability.ArkUI.ArkUI.Full

名称 参数类型 必填 说明
title string 否 标题文本。
buttons [Button](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.2-Beta1/zh-cn/application-dev/reference/apis/js-apis-system-prompt.md#button), [Button](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.2-Beta1/zh-cn/application-dev/reference/apis/js-apis-system-prompt.md#button)?, [Button](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.2-Beta1/zh-cn/application-dev/reference/apis/js-apis-system-prompt.md#button)?, [Button](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.2-Beta1/zh-cn/application-dev/reference/apis/js-apis-system-prompt.md#button)?, [Button](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.2-Beta1/zh-cn/application-dev/reference/apis/js-apis-system-prompt.md#button)?, [Button](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.2-Beta1/zh-cn/application-dev/reference/apis/js-apis-system-prompt.md#button)? 是 对话框中按钮的数组,结构为:{text:'button', color: '#666666'},支持1-6个按钮。
success (tapIndex: number, errMsg: string) => void 否 弹出对话框时调用。
fail (errMsg: string) => void 否 接口调用失败的回调函数。
complete (data: string) => void 否 关闭对话框时调用。
相关推荐
行者-全栈开发6 小时前
【鸿蒙心迹】国际化 i18n 与多语言资源管理实战(HarmonyOS 7.x)
ui·华为·重构·国际化·harmonyos·多语言
积流成海7 小时前
Agent演化史(九):多智能体的暗面,当一次 prompt 注入可以横向移动
prompt·agent·智能体·大模型应用
OH_TPC8 小时前
HarmonyOS APP开发---"云客服"远程视频客服App,需要用到这个库
harmonyos
深蓝AI10 小时前
Agent 查数据库先问口径再动手:NVIDIA 开源语义层 Auto Ontology,连续两天登顶 GitHub Python 趋势榜
人工智能·程序员
逆回1 天前
给鸿蒙手机做一只 3D 宠物:五个把我卡住的问题
harmonyos
高晶1 天前
Android 任务管理器开发实战指南
程序员
钉先生贾1 天前
性能、体积与稳定性:怎样写出可信的适配结论
华为·harmonyos
笑 总不会犯错1 天前
摆脱多端数据撕裂,鸿蒙分布式数据库同步与冲突合并
harmonyos
用户117910488331 天前
鸿蒙签名失败不是玄学:5 个证据点把 hapsigntool 一次排通 GitHub:swsgbl/hmharness
开源·ai编程·harmonyos
楠风测开1 天前
Web 兼容性 + AI 跨浏览器
程序员