鸿蒙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%')
  }
}
相关推荐
想你依然心痛1 小时前
HarmonyOS 5.0车机应用开发实战:基于方舟引擎的智能座舱多模态交互系统
华为·交互·harmonyos
前端郭德纲1 小时前
JavaScript原生开发与鸿蒙原生开发对比
开发语言·javascript·harmonyos
木斯佳4 小时前
HarmonyOS 6实战:图片验证码迁移报错的复盘思考
harmonyos·验证码·人机校验
枫叶丹44 小时前
【HarmonyOS 6.0】ArkUI 状态管理进阶:深入理解 @Consume 装饰器默认值特性
开发语言·华为·harmonyos
HwJack204 小时前
HarmonyOS Wear Engine Kit:让智能手表应用“活”起来的魔法工具箱
华为·harmonyos·智能手表
枫叶丹44 小时前
【HarmonyOS 6.0】ArkUI SymbolGlyph 进阶:快速替换动效、阴影、渐变与动效控制详解
华为·harmonyos
枫叶丹45 小时前
【HarmonyOS 6.0】ArkUI 闪控球功能深度解析:从API到实战
开发语言·microsoft·华为·harmonyos
qq_553760325 小时前
Harmony OS 图片下载功能全解析
华为·harmonyos·鸿蒙
Swift社区6 小时前
鸿蒙游戏中的多端适配策略
游戏·华为·harmonyos
IsITGirl15 小时前
已配置签名仍显示未签名导致安装失败
harmonyos