1 Star 0 Fork 5.3K

OpenHarmony-build / docs

forked from OpenHarmony / docs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ts-methods-alert-dialog-box.md 24.41 KB
一键复制 编辑 原始数据 按行查看 历史
zengyawen 提交于 2021-11-10 20:02 . add arkui

警告弹窗

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

属性

名称

参数类型

默认值

参数描述

show

options: { paramObject1| paramObject2}

-

定义并显示AlertDialog组件。

  • paramObject1参数

    参数名

    参数类型

    必填

    默认值

    参数描述

    title

    string | Resource

    -

    弹窗标题。

    message

    string | Resource

    -

    弹窗内容。

    autoCancel

    boolean

    true

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

    confirm

    {

    value: string | Resource,

    fontColor?: Color | number | string | Resource,

    backgroundColor?: Color | number | string | Resource,

    action: () => void

    }

    -

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

    cancel

    () => void

    -

    点击遮障层关闭dialog时的回调。

    alignment

    DialogAlignment

    DialogAlignment.Default

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

    offset

    {

    dx: Length | Resource,

    dy: Length | Resource

    }

    -

    弹窗相对alignment所在位置的偏移量。

    gridCount

    number

    -

    弹窗容器宽度所占用栅格数。

  • paramObject2参数

    参数名

    参数类型

    必填

    默认值

    参数描述

    title

    string | Resource

    -

    弹窗标题。

    message

    string | Resource

    -

    弹窗内容。

    autoCancel

    boolean

    true

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

    primaryButton

    {

    value: string | Resource,

    fontColor?: Color | number | string | Resource,

    backgroundColor?: Color | number | string | Resource,

    action: () => void;

    }

    -

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

    secondaryButton

    {

    value: string | Resource,

    fontColor?: Color | number | string | Resource,

    backgroundColor?: Color | number | string | Resource,

    action: () => void;

    }

    -

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

    cancel

    () => void

    -

    点击遮障层关闭dialog时的回调。

    alignment

    DialogAlignment

    DialogAlignment.Default

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

    offset

    {

    dx: Length | Resource,

    dy: Length | Resource

    }

    -

    弹窗相对alignment所在位置的偏移量。

    gridCount

    number

    -

    弹窗容器宽度所占用栅格数。

示例

@Entry
@Component
struct AlertDialogExample {
  build() {
    Column({ space: 5 }) {
      Button('one button dialog')
        .onClick(() => {
          AlertDialog.show(
            {
              title: 'title',
              message: 'text',
              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',
              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
https://gitee.com/openharmony-build/docs.git
git@gitee.com:openharmony-build/docs.git
openharmony-build
docs
docs
master

搜索帮助