鸿蒙语言基础类库:【@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, Button?, 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, Button?, Button?, Button?, Button?, Button?] 对话框中按钮的数组,结构为:{text:'button', color: '#666666'},支持1-6个按钮。
success (tapIndex: number, errMsg: string) => void 弹出对话框时调用。
fail (errMsg: string) => void 接口调用失败的回调函数。
complete (data: string) => void 关闭对话框时调用。
相关推荐
川川菜鸟42 分钟前
2024华为杯E题:高速公路应急车道紧急启用模型
华为
迷途小书童的Note5 小时前
超级Prompt!
prompt·dreamweaver
爱数模的小云5 小时前
【华为杯】2024华为杯数模研赛D题 解题思路
算法·华为
CS数模5 小时前
2024 “华为杯” 中国研究生数学建模竞赛(D题)深度剖析|大数据驱动的地理综合问题|数学建模完整代码+建模过程全解全析
大数据·数学建模·华为
CS数模5 小时前
2024 “华为杯” 中国研究生数学建模竞赛(E题)深度剖析|高速公路应急车道启用建模|数学建模完整代码+建模过程全解全析
数学建模·华为
DS数模6 小时前
2024华为杯研究生数学建模竞赛(研赛)选题建议+初步分析
数学建模·华为·华为杯·研赛·华为杯数学建模竞赛
OH五星上将6 小时前
OpenHarmony(鸿蒙南向开发)——标准系统方案之瑞芯微RK3568移植案例(下)
linux·驱动开发·嵌入式硬件·harmonyos·openharmony·鸿蒙开发·系统移植
余生爱静6 小时前
纯血鸿蒙NEXT常用的几个官方网站
华为·harmonyos
让开,我要吃人了7 小时前
HarmonyOS鸿蒙开发实战(5.0)网格元素拖动交换案例实践
前端·华为·程序员·移动开发·harmonyos·鸿蒙·鸿蒙开发
PlumCarefree10 小时前
鸿蒙手势交互(三:组合手势)
华为·交互·harmonyos