鸿蒙OS promptAction的使用

复制代码
效果如下:
复制代码
import { promptAction } from '@kit.ArkUI'

let customDialogId: number = 0

@Builder
function customDialogBuilder() {
  Column() {
    Blank().height(30)
    Text('确定要删除吗?').fontSize(15)
    Blank().height(40)
    Row() {
        Button("取消").onClick(() => {
          promptAction.closeCustomDialog(customDialogId)
        })
        .width(80).height(30)
        .fontColor($r("app.color.btn_button"))
        .backgroundColor($r('app.color.white'))
      Blank().width(50)
      Button("确认").onClick(() => {
        promptAction.closeCustomDialog(customDialogId)
      })
        .backgroundColor($r("app.color.btn_button"))
        .fontColor($r('app.color.white'))
     .width(80).height(30)
    }
  }
}



@Entry
@Component
struct CustomDialog {
  @State message: string = 'Hello World'

  @Builder
  customDialogComponent() {
    customDialogBuilder()
  }

  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
          .onClick(() => {
            promptAction.openCustomDialog({
              builder: () => {
                this.customDialogComponent()
              },
              showInSubWindow: false,
              offset: { dx: 5, dy: 5 },
              backgroundColor: 0xd9ffffff,
              cornerRadius: 20,
              width: '80%',
              height: 150,
              borderWidth: 1,
              borderColor:$r('app.color.white'), //使用borderColor属性,需要和borderWidth属性一起使用
              shadow: ({
                radius: 20,
                color: Color.Grey,
                offsetX: 50,
                offsetY: 0
              }),
            }).then((dialogId: number) => {
              customDialogId = dialogId
            })
          })
      }
      .width('100%')
    }
    .height('100%')
  }
}
相关推荐
事界见闻7 小时前
鸿蒙6闪控球功能评测:盯盘、抢单、搜题,一点即达
华为·harmonyos
李二。9 小时前
ArkTS原生 | 知识问答引擎 —— 鸿蒙Next声明式UI实战
ui·华为·harmonyos
坚果的博客9 小时前
【鸿蒙 PC三方库构建系统】【测试验证】HPKCHECK文件详解
华为·harmonyos
世人万千丶9 小时前
鸿蒙PC问题解决:窗口拖动与拉伸时页面布局瞬间错乱、回弹后恢复
学习·华为·开源·harmonyos·鸿蒙·鸿蒙系统
Dream-Y.ocean10 小时前
Windows 鸿蒙 PC 应用开发:Electron 桌面级电子书阅读器开发实战指南
华为·harmonyos
浮芷.11 小时前
鸿蒙PC端 TTS 语音播放失败问题详解:从错误码到解决方案
华为·开源·harmonyos·鸿蒙·鸿蒙系统
提子拌饭13311 小时前
模态窗鸿蒙PC Electron框架实现技术详解 - 饮料含糖量应用案例分析
前端·javascript·华为·electron·前端框架·开源·鸿蒙
浮芷.11 小时前
鸿蒙PC端 TTS 网络连接错误问题详解:在线/离线模式切换与网络状态管理
网络·华为·开源·harmonyos·鸿蒙·鸿蒙系统
免费gpt4分享12 小时前
我主动放弃了一半用户,只为了给剩下的人做一个95分的功能
harmonyos
世人万千丶14 小时前
鸿蒙 PC 避坑:DevEco Studio运行hdc命令执行异常完全指南
华为·开源·harmonyos·鸿蒙·鸿蒙系统