鸿蒙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%')
  }
}
相关推荐
全栈开发圈42 分钟前
新书速览|鸿蒙HarmonyOS 6开发之路 卷3:项目实践篇
鸿蒙·鸿蒙系统
FrameNotWork2 小时前
HarmonyOS 教学实战(六):复杂表单与校验体系(把“最难写”的模块写优雅)
华为·harmonyos
HMS Core3 小时前
【FAQ】HarmonyOS SDK 闭源开放能力 — Form Kit
华为·harmonyos
IT充电站4 小时前
鸿蒙应用开发之鸿蒙沙箱文件如何存媒体库?
harmonyos
IT充电站4 小时前
鸿蒙应用开发之通过AVPlayer如何实现音乐播放、暂停、音量设置?
harmonyos
HMS Core4 小时前
【FAQ】HarmonyOS SDK 闭源开放能力 — Share Kit
华为·harmonyos
昼-枕6 小时前
鸿蒙Flutter实战:构建智能健身教练应用
flutter·华为·harmonyos
昼-枕6 小时前
鸿蒙与 Flutter 的融合探索:跨平台开发的新可能
flutter·华为·harmonyos
特立独行的猫a6 小时前
鸿蒙PC三方库移植:zlib数据压缩库的适配实践
华为·harmonyos·移植·zlib·鸿蒙pc
AirDroid_cn6 小时前
鸿蒙NEXT:平板作为扩展屏时,触摸延迟如何优化?
华为·电脑·harmonyos