全局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、效果图

相关推荐
m0_7496902321 分钟前
HarmonyOS 本地备份与系统备份:BackupExtensionAbility、快照导出和恢复
harmonyos
心中有国也有家30 分钟前
AtomGit Flutter 鸿蒙客户端:情绪日记的时间线实现
学习·flutter·华为·harmonyos
澹然疏离42 分钟前
HarmonyOS应用《民族图鉴》开发第33篇:StorageService——本地存储服务封装
harmonyos
Nturmoils1 小时前
Agent 不只是聊天框:用 ArkUI 做一个鸿蒙任务工作台
harmonyos
GitCode官方1 小时前
开源鸿蒙跨平台直播| RN 三方库开源鸿蒙标准化适配实战分享
华为·开源·harmonyos·atomgit
不才难以繁此生4 小时前
ArkUI 列表性能实战|中式美食菜谱列表如何拆组件、控重绘和稳住滑动体验
harmonyos·arkts·状态管理·foreach·arkui·列表性能·组件拆分
Ww.xh4 小时前
DevEco Studio虚拟机部署指南
华为·harmonyos
yuanlaile4 小时前
前端转 Flutter 踩坑实录:一套可落地 Flutter 鸿蒙 App 完整学习路线,建议收藏!
flutter·harmonyos·flutter开发鸿蒙·跨平台开发app·flutter深入学习
FrameNotWork4 小时前
HarmonyOS 6.1 数据持久化与首选项实战:Preferences 和 RDB 的那些坑
华为·harmonyos
爸爸6194 小时前
08 ArkTS 类与静态方法设计:单例、DAO 与设计令牌
华为·harmonyos·鸿蒙系统