HarmonyOS中的@ohos.promptAction 模块中弹框

在各种APP中会根据不同的业务场景显示不同的弹框情况,针对这些场景API中提示了那些弹框呢?今天就看下:

首先弹框分为模态弹框和非模态弹框,模态弹框必须用户点击反馈后进行下一步操作,非模态弹框只是告知用户信息,并不需要用户操作也可以执行下一步操作。
弹框一:Toast它弹出一个小信息,作为提醒或消息反馈来用,一般用来显示操作结果,或者应用状态的改变

kotlin 复制代码
 promptAction.showToast({
              message: 'Message Info',// 信息
              duration: 2000,// 持续时间
              bottom:20,//距离底部位置
            });

弹框二:Dialog对话框 是一种模态弹窗。当用户进行了敏感操作,或者当App内部发生了较为严重的状态改变

kotlin 复制代码
promptAction.showDialog({
            title: "警告弹框",
            message: '你确定要返回上一页吗?',
            buttons: [
              {
                text: '取消',
                color: '#FF0000'
              },
              {
                text: '确认',
                color: '#0099FF'
              },
            ],

          }).then((result) => {
            if (result.index === 0) {
              // 用户点击了"取消"按钮
              console.info('User canceled the operation.');
            } else if (result.index === 1) {
              // 用户点击了"确认"按钮
              console.info('User confirmed the operation.');
              // 调用router.back()方法,返回上一个页面
            }
          }).catch((err) => {
            console.error(`Invoke showDialog failed, code is ${err.code}, message is ${err.message}`);
          })
        })

**弹框二:ActionMenu对话框类似安卓的Actionbar ** 最多可以定义6个Item,如果超过6个,将无法运行

Button("ActionMenu").buttonStyle()

.onClick(()=>{

promptAction.showActionMenu({

title: '这是一个选择框弹框',// 信息

buttons: [

{

text: 'item1',

color: '#666666',

},

{

text: 'item2',

color: '#000000',

},

{

text: 'item3',

color: '#666666',

},

{

text: 'item4',

color: '#666666',

},

{

text: 'item5',

color: '#666666',

},

{

text: 'item6',

color: '#666666',

},

]

}).then(data =>{

console.info("按钮选择框"+data.index)

});

});

本章节的弹框功能是 @ohos.promptAction 模块里提供的 API 显示的功能,下一章节讲解全局对话框

相关推荐
TT_Close5 小时前
【Flutter×鸿蒙】debug 包也要签名,这点和 Android 差远了
android·flutter·harmonyos
TT_Close21 小时前
【Flutter×鸿蒙】FVM 不认鸿蒙 SDK?4步手动塞进去
flutter·swift·harmonyos
hqk1 天前
鸿蒙项目实战:手把手带你实现 WanAndroid 布局与交互
android·前端·harmonyos
TT_Close1 天前
【Flutter×鸿蒙】一个"插队"技巧,解决90%的 command not found
flutter·harmonyos
Hcourage2 天前
鸿蒙工程获取C/C++代码覆盖
harmonyos
二流小码农2 天前
鸿蒙开发:上传一张参考图片便可实现页面功能
android·ios·harmonyos
万少3 天前
HarmonyOS 开发必会 5 种 Builder 详解
前端·harmonyos
Huang兄3 天前
鸿蒙-List和Grid拖拽排序:仿微信小程序删除效果
harmonyos·arkts·arkui
anyup4 天前
🔥2026最推荐的跨平台方案:H5/小程序/App/鸿蒙,一套代码搞定
前端·uni-app·harmonyos
Ranger09294 天前
鸿蒙开发新范式:Gpui
rust·harmonyos