在duyu200上体验eTS-警告弹窗

描述

今天开发板到手了,于是想体验一些新的东西。于是就从弹窗做起。

显示警告弹窗组件,可设置文本内容与响应回调。 从API Version 7开始支持

属性

名称 参数类型 默认值 参数描述
show options: { paramObject1| paramObject2} - 定义并显示AlertDialog组件

 

paramObject1参数

参数名 参数类型 必填 默认值 参数描述
title string - 弹窗标题。
message string - 弹窗内容。
autoCancel boolean true 点击遮障层时,是否关闭弹窗。
confirm { value: string |, fontColor?: Color | number | string | , backgroundColor?: Color | number | string | , action: () => void } - 确认按钮的文本内容、文本色、按钮背景色和点击回调。
cancel () => void - 点击遮障层关闭dialog时的回调。
alignment DialogAlignment DialogAlignment.Default 弹窗在竖直方向上的对齐方式。
offset { dx: Length | , dy: Length | } - 弹窗相对alignment所在位置的偏移量。
gridCount number - 弹窗容器宽度所占用栅格数。

paramObject2参数

参数名 参数类型 必填 默认值 参数描述
title string - 弹窗标题。
message string - 弹窗内容。
autoCancel boolean true 点击遮障层时,是否关闭弹窗。
primaryButton { value: string | fontColor?: Color | number | string | , backgroundColor?: Color | number | string | , action: () => void; } - 按钮的文本内容、文本色、按钮背景色和点击回调。
secondaryButton { value: string | , fontColor?: Color | number | string | , backgroundColor?: Color | number | string | , action: () => void; } - 按钮的文本内容、文本色、按钮背景色和点击回调。
cancel () => void - 点击遮障层关闭dialog时的回调。
alignment DialogAlignment DialogAlignment.Default 弹窗在竖直方向上的对齐方式。
offset { dx: Length | , dy: Length |} - 弹窗相对alignment所在位置的偏移量。
gridCount number - 弹窗容器宽度所占用栅格数。

案例

@Entry

@Component

struct AlertDialogExample {

  build() {

    Column({ space: 50}) {

      Button('one button')

        .onClick(() => {

          AlertDialog.show(

            {

              title: '弹窗标题',

              message: '弹窗内容',

              autoCancel:false,

              confirm: {

                value: '确认按钮的文本内容',

​

                action: () => {

                  console.info('Button-clicking callback')

                }

              },

              cancel: () => {

                console.info('Closed callbacks')

              }

            }

          )

        })

        .backgroundColor(0x317aff)

      Button('two button ')

        .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: 500 })

  }

}

 

效果图:

开发板开发板开发板

然后我们可以运行在真机上。

开发板

 

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分