鸿蒙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 分钟前
【HarmonyOS 7新能力|011】分布式数字身份入门实战:从能力边界到最小可运行链路
harmonyos·arkts·隐私保护·数字身份·harmonyos 7
颜颜yan_11 分钟前
Geany 鸿蒙 PC 适配全记录:以 Qt 重建轻量 IDE,打通编辑、项目检索与命令执行
ide·qt·harmonyos
●VON13 分钟前
Flutter 鸿蒙插件适配实战:用 app_version_details 1.0.3 读取版本号与包名
flutter·华为·harmonyos
承渊政道25 分钟前
PR-Agent鸿蒙PC适配全记录:从Python服务端代理到ArkTS原生评审客户端
python·华为·代理模式·agent·harmonyos·pc端
忆凡_32 分钟前
Dyad 鸿蒙 PC 适配全记录:让本地 AI 应用构建器进入 HarmonyOS PC
electron·鸿蒙
网络豆1 小时前
Apache Hive 鸿蒙 PC 适配全记录:以 Qt 客户端打通 HiveQL、监控与元数据访问
hive·apache·harmonyos
网络豆1 小时前
Apache HBase 鸿蒙 PC 适配全记录:用 Qt 原生客户端打通 REST 管理与数据读写
apache·hbase·harmonyos
hacker7072 小时前
bolt.diy 鸿蒙 PC 适配全记录:让 AI 全栈开发工作台在 HarmonyOS PC 上真正跑起来
人工智能·华为·harmonyos
●VON3 小时前
Flutter 鸿蒙插件适配实战:用 locale_plus 2.0.0 读取语言、地区与格式偏好
flutter·华为·harmonyos·鸿蒙
贾伟康12 小时前
【HarmonyOS 7新能力|008】互动卡片入门实战:从能力边界到最小可运行链路
harmonyos·arkts·arkui·harmonyos 7·互动卡片