鸿蒙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 小时前
鸿蒙5.1.0及ArkTS新特性
harmonyos·arkts
鸿蒙小灰1 小时前
鸿蒙开发K线图实现思路
harmonyos
小小小小小星1 小时前
鸿蒙原子化服务(Service Card)开发指南:从入门到实战
harmonyos
kymjs张涛3 小时前
零一开源|前沿技术周刊 #13
ios·harmonyos·apple
缘澄7 小时前
组件基础-List&Tabs
harmonyos
爱笑的眼睛1121 小时前
HarmonyOS TextArea 组件:文本输入区域的简单使用指南
华为·harmonyos
前端世界21 小时前
鸿蒙异步处理从入门到实战:Promise、async/await、并发池、超时重试全套攻略
华为·harmonyos
祥睿夫子1 天前
鸿蒙ArkTS开发:Number、Boolean、String三种核心基本数据类型详解(附实战案例)
harmonyos·arkts
小喷友1 天前
第5章 高级UI与动画
前端·app·harmonyos
whysqwhw1 天前
鸿蒙ArkTS 与 Native 交互场景分类总结与关键实现
harmonyos