鸿蒙开发:弹窗交互(promptAction )
2024-12-24 22:57:42
314次阅读
0个评论
实现效果
- 点击按钮实现不同方式的弹窗
- showToast
- showDialog
 
- showActionMenu
 
代码实现
- 引入'@ohos.promptAction'
import promptAction from '@ohos.promptAction';
- 通过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%')
  }
}
00
- 0回答
- 0粉丝
- 0关注
相关话题
- 鸿蒙开发:实现popup弹窗
- 鸿蒙隐私弹窗功能开发实践
- 开发者工具箱-鸿蒙弹窗使用指南
- 《HarmonyOSNext弹窗:ComponentContent动态玩转企业级弹窗》
- 自定义组件之<五>自定义对话框(PromptAction)
- (二六)ArkTS 智能语音交互开发
- 《仿盒马》app开发技术分享-- 商品规格弹窗(11)
- (三六)ArkTS 与物联网设备交互开发
- HarmonyOS Next 弹窗系列教程(3)
- HarmonyOS Next 弹窗系列教程(4)
- HarmonyOS Next 弹窗系列教程(5)
- HarmonyOS Next 弹窗系列教程(1)
- HarmonyOS Next 弹窗系列教程(2)
- 《仿盒马》app开发技术分享-- 分类模块顶部导航列表弹窗(16)
- harmony-utils之DialogUtil,弹窗工具类

