全局UI方法-弹窗二-列表选择弹窗(ActionSheet)

1、描述

定义列表弹窗

2、接口

ActionSheet.show(value:{

title: string | Resource,

message: string | Resource,

autoCancel?: boolean,

confrim?: {value: string | Resource, action: () => void },

cancel?: () => void,

alignment?: DialogAlignment,

offset?: {dx: Length, dy: Length } ,

sheets: Array<SheetInfo>

})

3、参数

名称 类型 必填 说明
title string | Resource 弹窗标题。
message string | Resource 弹窗内容。
autoCancel boolean 点击遮障层(弹窗之外的空白区域)时,是否关闭弹窗。 默认值:true。
confirm { value: string | Resource, action: () => void } 确认按钮的文本内容,文本颜色,按钮背景色以及点击回调。
cancel () => void 点击遮障层关闭Dialog时的回调。
alignment DialogAlignment 弹窗在竖直方向上的对其方式。默认值:DialogAlignment.Default。
offset { dx: Length, dy: Length } 弹窗相对于alignment所在位置的偏移量。
sheets Array<sheetInfo> 设置选项内容,每个选择项支持设置图片、文本和选中的回调。

4、sheetInfo对象说明:

5、示例

复制代码
@Entry
@Component
struct ActionSheetPage {
  @State message: string = '定义列表弹窗'

  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(20)
          .fontWeight(FontWeight.Bold)
          .width("96%")
          .margin({ top: 12 })

        Button("ActionSheet.show")
          .width("96%")
          .fontSize(20)
          .margin({ top: 12 })
          .onClick(() => {
            ActionSheet.show({
              title: "ActionSheet",
              message: "定义列表弹窗",
              autoCancel: true,
              confirm: { value: "确认", action: () => {
                console.info("ActionSheetPage click confirm");
              } },
              cancel: () => {
                console.info("ActionSheetPage autoCancel is true click cancel");
              },
              alignment: DialogAlignment.Bottom,
              offset: { dx: 0, dy: -20 },
              sheets: [{
                title: 'Android',
                action: () => {
                  console.log('Android')
                }
              },
                {
                  title: 'Java',
                  action: () => {
                    console.log('Java')
                  }
                },
                {
                  title: 'IOS',
                  action: () => {
                    console.log('IOS')
                  }
                },
                {
                  title: 'Python',
                  action: () => {
                    console.log('Python')
                  }
                },
                {
                  title: 'Vue',
                  action: () => {
                    console.log('Vue')
                  }
                },
                {
                  title: 'ArkTS',
                  action: () => {
                    console.log('ArkTS')
                  }
                }
              ]
            })
          })

      }
      .width('100%')
      .height("100%")
    }
    .height('100%')
  }
}

6、效果图

相关推荐
jackchen5552 小时前
华为Esight23.1安装及交换机接入教程
网络·华为
嘴平伊之豬3 小时前
对照typescript学习鸿蒙ArkTS
前端·harmonyos
威哥爱编程4 小时前
【鸿蒙开发案例篇】NAPI 实现 ArkTS 与 C++ 间的复杂对象传递
c++·harmonyos·arkts
优质网络系统领域创作者4 小时前
华为链路聚合原理
人工智能·华为
ShuiShenHuoLe5 小时前
鸿蒙6应用内集成防窥保护
ubuntu·华为·harmonyos
500845 小时前
鸿蒙 Flutter 接入鸿蒙系统能力:通知(本地 / 推送)与后台任务
java·flutter·华为·性能优化·架构
盐焗西兰花6 小时前
鸿蒙学习实战之路 - 应用间链接最佳实践
学习·华为·harmonyos
大雷神6 小时前
[鸿蒙2025领航者闯关]HarmonyOS中开发高德地图第三篇:地图控制与UI设置
harmonyos
人工智能训练6 小时前
openEuler系统中home文件夹下huawei、HwHiAiUser、lost+found 文件夹的区别和作用
linux·运维·服务器·人工智能·windows·华为·openeuler
●VON16 小时前
从单机应用到分布式调度:基于 HarmonyOS 构建车-空协同任务引擎
学习·华为·harmonyos·openharmony·开源鸿蒙