【HarmonyOS开发】弹窗交互(promptAction )
创始人
2025-01-09 10:37:43
0次

实现效果

  • 点击按钮实现不同方式的弹窗
  • showToast
    在这里插入图片描述
  • showDialog
    在这里插入图片描述
  • showActionMenu
    在这里插入图片描述

代码实现

1.引入’@ohos.promptAction’

import promptAction from '@ohos.promptAction'; 

2.通过promptAction 实现系统既定的弹窗

import promptAction from '@ohos.promptAction';  @Entry @Component struct Show_Page {   @State message: string = 'Hello World';    showToast() {     promptAction.showToast({       message: "登录成功", //显示内容       duration: 2000, //显示持续时间       bottom: 400//设置显示的距离底部位置     })   }    showDialog() {     promptAction.showDialog({       title: "提示",       message: "您确定要删除嘛?",       buttons: [         {           text: "取消",           color: "#000"         },         {           text: "确定",           color: "#000"         }       ]      }).then((data) => {       console.log(data.index.toString());     })   }    showActionMenu() {     promptAction.showActionMenu({       title: "选择字体",       buttons: [         {           text: "测试1",           color: "#ccc"         },         {           text: "测试2",           color: "#ccc"         },         {           text: "测试3",           color: "#ccc"         },         {           text: "测试4",           color: "#ccc"         },         {           text: "测试5",           color: "#ccc"         }       ]     }).then((data) => {       console.log(data.index.toString());     })   }    build() {     Column() {       Button() {         Text("ShowToast").fontColor(Color.White).fontSize(18)       }       .width("90%")       .height(40)       .margin({ top: 40 })       .onClick(() => {         this.showToast();       })        Button() {         Text("ShowDialog").fontColor(Color.White).fontSize(18)       }       .width("90%")       .height(40)       .margin({ top: 40 })       .onClick(() => {         this.showDialog();       })        Button() {         Text("ShowActionMenu").fontColor(Color.White).fontSize(18)       }       .width("90%")       .height(40)       .margin({ top: 40 })       .onClick(() => {         this.showActionMenu();       })     }     .height('100%')     .width('100%')   } } 

相关内容

热门资讯

2027版开挂!廊坊麻将鲨鱼互... 2027版开挂!廊坊麻将鲨鱼互动开挂多功能AI教程,廊坊麻将鲨鱼互动都是是有开挂教程小薇(辅助器软件...
2027版透视挂!众乐贵州麻将... 2027版透视挂!众乐贵州麻将透视挂多功能AIapp,众乐贵州麻将竟然是真的有透视挂app1、下载好...
2027版外挂!山西扣点点外挂... 2027版外挂!山西扣点点外挂多功能AI攻略,山西扣点点其实存在有外挂攻略1、完成山西扣点点有辅助插...
2027版透视器!同仁棋牌透视... 2027版透视器!同仁棋牌透视器多功能AI插件,同仁棋牌确实真的有透视器插件1、打开软件启动之后找到...
2027版辅助器!朋朋棋牌辅助... 2027版辅助器!朋朋棋牌辅助器多功能AI工具,朋朋棋牌本来真的有辅助器工具朋朋棋牌是不是有人用挂微...
2027版透视挂!微乐郑州麻将... 2027版透视挂!微乐郑州麻将透视挂多功能AI方法,微乐郑州麻将原来存在有透视挂方法1、微乐郑州麻将...
2027版作弊器!旺旺南平麻将... 2027版作弊器!旺旺南平麻将作弊器多功能AI脚本,旺旺南平麻将切实真的是有作弊器脚本旺旺南平麻将辅...
2027版透视器!上豫洛阳麻将... 2027版透视器!上豫洛阳麻将透视器多功能AI工具,上豫洛阳麻将都是存在有透视器工具1、玩家可以在上...
2027版辅助!血战到底麻将辅... 2027版辅助!血战到底麻将辅助多功能AI攻略,血战到底麻将原来是真的有辅助攻略运血战到底麻将辅助工...
2027版开挂!柳州红中麻将开... 2027版开挂!柳州红中麻将开挂多功能AI软件,柳州红中麻将都是存在有开挂软件1、全新机制【柳州红中...