鸿蒙语言基础类库:【@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 关闭对话框时调用。
相关推荐
大模型码小白12 小时前
AI大模型接入SDK:人工智能核心概念与发展史
大数据·运维·人工智能·安全·prompt
小小小小钰儿14 小时前
1.2-AI核心理论与术语
人工智能·计算机·网络安全·信息安全·程序员·编程
AI备忘录17 小时前
(十九)华为华三锐捷迈普思科 交换机链路聚合配置命令(LACP/静态聚合五厂商对照)
运维·服务器·网络·网络协议·tcp/ip·华为
贾伟康18 小时前
【时光清单|19】HarmonyOS ArkTS 回归测试实战:覆盖启动、空数据、异常输入和重复点击
软件测试·harmonyos·arkts·回归测试·hypium
坚果的博客18 小时前
Flutter OHOS 环境搭建实战:oh-3.44.9-dev 从 0 到 1 完整记录
flutter·华为·harmonyos
坚果的博客18 小时前
认识 CPF-RN:React Native 鸿蒙官方社区与四大核心仓库
react native·react.js·harmonyos
大雷神20 小时前
HarmonyOS ArkGraphics 2D可变帧率实操——同屏对比30、60和90 FPS动画
华为·harmonyos
OH_TPC20 小时前
【鸿蒙优选三方库】@react-native-ohos/react-native-fast-image:高性能图片加载与缓存组件
缓存·华为·harmonyos·鸿蒙
贾伟康21 小时前
【句匠|03】HarmonyOS ArkTS 每日打卡实战:实现连续天数、补签边界和本地日期判断
harmonyos·arkts·本地存储·每日打卡·学习应用
小雨青年21 小时前
【HarmonyOS 7 平行视界深度实战】02 从普通页面到第一个平行视界 Demo
华为·harmonyos