鸿蒙语言基础类库:【@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 否 关闭对话框时调用。
相关推荐
马剑威(威哥爱编程)9 小时前
【共创稿事节】HarmonyOS 7 Agent 开发实战 11:并发多会话隔离
华为·harmonyos
高晶11 小时前
ARM 嵌入式 Linux 文件系统从入门到实战:目录结构、权限管理、选型与挂载排查全攻略
linux·程序员
米米商聊11 小时前
语音进度显示 100%,为什么还不能判定播放结束?
程序员
高晶11 小时前
C 语言实现 BMS 系统中 SPI 通信协议实战指南
设计模式·程序员
用户3550901748611 小时前
工业 RAG 实战:忠实度从 0.85 调到 0.95,我们做对了这几件事
程序员
行者-全栈开发12 小时前
【共创稿事节】HarmonyOS 7 空间音频实战:用 AudioSpatializationManager 构建“听得见方位“的声场
harmonyos·arkts·鸿蒙·空间音频·api 26·audio kit
马剑威(威哥爱编程)13 小时前
【共创稿事节】HarmonyOS 7 Agent 开发实战 03:Tool Calling 让 AI 查实时订单与库存
华为·harmonyos
高晶13 小时前
Android 短信收发模块从零到实战:权限配置、界面设计、发送接收与兼容性适配全攻略
android·程序员
倔强的石头10615 小时前
把 Typst 搬上开源鸿蒙 PC:一次“干净”的移植记录
华为·开源·harmonyos
梦想不只是梦与想17 小时前
鸿蒙 预览数据模拟:Hamock
harmonyos·模拟数据·hamock