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

相关推荐
2501_948122636 小时前
开源鸿蒙平台 CMP 三方库「kmp-showcase-compose」适配全流程
华为·开源·harmonyos
OH_TPC7 小时前
HarmonyOS APP开发---“旅图“旅行摄影社区App,需要用到这个库
华为·harmonyos·鸿蒙
独隅9 小时前
HarmonyOS 系统能力与体验深度评测
华为·harmonyos·harmonyos 7.0
2601_949575869 小时前
开源鸿蒙平台 CMP 三方库「Persian-Date-picker」适配全流程
华为·开源·harmonyos
KevinChaos10 小时前
灶台菜谱设计手记 02|HarmonyOS 7.0 空间化:菜图滚动实现
harmonyos
独隅11 小时前
HarmonyOS 全场景智能应用落地指南
华为·harmonyos·harmonyos 7.0
熊猫钓鱼>_>11 小时前
鸿蒙PC构建实战:hvigor modelVersion 降级 + schema 清理 + ArkTS 编译三连坑完整复盘
开发语言·华为·ai编程·harmonyos·openharmony·数据·ai生成
2601_9499706911 小时前
开源鸿蒙平台 CMP 三方库「SaltUI」适配全流程
华为·开源·harmonyos
马剑威(威哥爱编程)11 小时前
【HarmonyOS 7 小艺智能体实战】06:VibeCoding 十分钟搓出一个 Skill(上)——从想法到生成
人工智能·华为·harmonyos
马剑威(威哥爱编程)12 小时前
【HarmonyOS 7 小艺智能体实战】07:手写一个 Skill(下)——ArkTS、意图框架与工程结构
人工智能·华为·harmonyos