鸿蒙:警告弹窗

显示警告弹窗组件,可设置文本内容与响应回调。

说明:从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。

属性

名称 参数类型 参数描述
show AlertDialogParamWithConfirm | AlertDialogParamWithButtons 定义并显示AlertDialog组件。

AlertDialogParamWithConfirm对象说明

参数名 参数类型 必填 参数描述
title ResourceStr 弹窗标题。
message ResourceStr 弹窗内容。
autoCancel boolean

点击遮障层时,是否关闭弹窗。

默认值:true

confirm

{

value: ResourceStr,

fontColor?: ResourceColor,

backgroundColor?: ResourceColor,

action: () => void

}

确认按钮的文本内容、文本色、按钮背景色和点击回调。
cancel () => void 点击遮障层关闭dialog时的回调。
alignment DialogAlignment

弹窗在竖直方向上的对齐方式。

默认值:DialogAlignment.Default

offset Offset 弹窗相对alignment所在位置的偏移量。
gridCount number 弹窗容器宽度所占用栅格数。

AlertDialogParamWithButtons对象说明

参数名 参数类型 必填 参数描述
title ResourceStr 弹窗标题。
message ResourceStr 弹窗内容。
autoCancel boolean

点击遮障层时,是否关闭弹窗。

默认值:true

primaryButton

{

value: ResourceStr,

fontColor?: ResourceColor,

backgroundColor?: ResourceColor,

action: () => void;

}

按钮的文本内容、文本色、按钮背景色和点击回调。
secondaryButton

{

value: ResourceStr,

fontColor?: ResourceColor,

backgroundColor?: ResourceColor,

action: () => void;

}

按钮的文本内容、文本色、按钮背景色和点击回调。
cancel () => void 点击遮障层关闭dialog时的回调。
alignment DialogAlignment

弹窗在竖直方向上的对齐方式。

默认值:DialogAlignment.Default

offset Offset 弹窗相对alignment所在位置的偏移量。
gridCount number 弹窗容器宽度所占用栅格数。

DialogAlignment枚举说明

名称 描述
Top 垂直顶部对齐。
Center 垂直居中对齐。
Bottom 垂直底部对齐。
Default 默认对齐。
TopStart8+ 左上对齐。
TopEnd8+ 右上对齐。
CenterStart8+ 左中对齐。
CenterEnd8+ 右中对齐。
BottomStart8+ 左下对齐。
BottomEnd8+ 右下对齐。
// xxx.ets
@Entry
@Component
struct AlertDialogExample {
  build() {
    Column({ space: 5 }) {
      Button('one button dialog')
        .onClick(() => {
          AlertDialog.show(
            {
              title: 'title',
              message: 'text',
              autoCancel: true,
              alignment: DialogAlignment.Bottom,
              offset: { dx: 0, dy: -20 },
              gridCount: 3,
              confirm: {
                value: 'button',
                action: () => {
                  console.info('Button-clicking callback')
                }
              },
              cancel: () => {
                console.info('Closed callbacks')
              }
            }
          )
        })
        .backgroundColor(0x317aff)
      Button('two button dialog')
        .onClick(() => {
          AlertDialog.show(
            {
              title: 'title',
              message: 'text',
              autoCancel: true,
              alignment: DialogAlignment.Bottom,
              gridCount: 4,
              offset: { dx: 0, dy: -20 },
              primaryButton: {
                value: 'cancel',
                action: () => {
                  console.info('Callback when the first button is clicked')
                }
              },
              secondaryButton: {
                value: 'ok',
                action: () => {
                  console.info('Callback when the second button is clicked')
                }
              },
              cancel: () => {
                console.info('Closed callbacks')
              }
            }
          )
        }).backgroundColor(0x317aff)
    }.width('100%').margin({ top: 5 })
  }
}

 

相关推荐

  1. 鸿蒙警告

    2024-03-14 22:40:02       29 阅读
  2. 鸿蒙OS应用开发之自定义

    2024-03-14 22:40:02       42 阅读
  3. 鸿蒙HarmonyOS开发笔记】如何自定义

    2024-03-14 22:40:02       47 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-14 22:40:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-14 22:40:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-14 22:40:02       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-14 22:40:02       20 阅读

热门阅读

  1. NLP:bert下载与使用

    2024-03-14 22:40:02       21 阅读
  2. LeetCode 1768. 交替合并字符串

    2024-03-14 22:40:02       17 阅读
  3. linux常用命令2

    2024-03-14 22:40:02       18 阅读
  4. 微信小程序-npm扩展工具包

    2024-03-14 22:40:02       21 阅读
  5. mapperXML标签总结

    2024-03-14 22:40:02       18 阅读
  6. 基于Node.js 和 FFmpeg构建自动化脚本用来转码视频

    2024-03-14 22:40:02       20 阅读