鸿蒙:列表选择弹窗

从API Version 8开始支持

ActionSheet.show

show(value: { title: string | Resource, message: string | Resource, confirm?: {value: string | Resource, action:() => void}, cancel?:()=>void, sheets: Array<SheetInfo>, autoCancel?:boolean, alignment?: DialogAlignment, offset?: { dx: number | string | Resource; dy: number | string | Resource } })

定义列表弹窗并弹出。

参数:

参数名参数类型必填参数描述
titleResource | string弹窗标题。
messageResource | string弹窗内容。
autoCancelboolean

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

默认值:true

confirm

{

value: ResourceStr,

action: () => void

}

确认按钮的文本内容和点击回调。

默认值:

value:按钮文本内容。

action: 按钮选中时的回调。

cancel() => void点击遮障层关闭dialog时的回调。
alignmentDialogAlignment

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

默认值:DialogAlignment.Bottom

offset

{

dx: Length,

dy: Length

}

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

dx: 0,

dy: 0

}

sheetsArray<SheetInfo>设置选项内容,每个选择项支持设置图片、文本和选中的回调。

SheetInfo接口说明

参数名参数类型必填参数描述
titleResourceStr选项的文本内容。
iconResourceStr选项的图标,默认无图标显示。
action()=>void选项选中的回调。
@Entry
@Component
struct ActionSheetExample {
  build() {
    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
      Button('Click to Show ActionSheet')
        .onClick(() => {
          ActionSheet.show({
            title: 'ActionSheet title',
            message: 'message',
            autoCancel: true,
            confirm: {
              value: 'Confirm button',
              action: () => {
                console.log('Get Alert Dialog handled')
              }
            },
            cancel: () => {
              console.log('actionSheet canceled')
            },
            alignment: DialogAlignment.Bottom,
            offset: { dx: 0, dy: -10 },
            sheets: [
              {
                title: 'apples',
                action: () => {
                  console.log('apples')
                }
              },
              {
                title: 'bananas',
                action: () => {
                  console.log('bananas')
                }
              },
              {
                title: 'pears',
                action: () => {
                  console.log('pears')
                }
              }
            ]
          })
        })
    }.width('100%')
    .height('100%')
  }
}

 

  • 7
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值