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

相关推荐
lili-felicity16 小时前
React Native 鸿蒙跨平台开发:LayoutAnimation 实现鸿蒙端按钮点击的缩放反馈动画
react native·react.js·harmonyos
C雨后彩虹18 小时前
竖直四子棋
java·数据结构·算法·华为·面试
m0_6855350818 小时前
华为光学工程师招聘
华为·光学·光学设计·光学工程·镜头设计
哈__18 小时前
React Native 鸿蒙跨平台开发:Dimensions 屏幕尺寸获取
react native·华为·harmonyos
奋斗的小青年!!19 小时前
Flutter跨平台开发适配OpenHarmony:手势识别实战应用
flutter·harmonyos·鸿蒙
搬砖的kk19 小时前
Cordova 适配鸿蒙系统(OpenHarmony) 全解析:技术方案、环境搭建与实战开发
华为·开源·harmonyos
不爱吃糖的程序媛19 小时前
OpenHarmony 通用C/C++三方库 标准化鸿蒙化适配
c语言·c++·harmonyos
程序猿追19 小时前
鸿蒙PC应用开发深度实战:一次开发、多端适配的沉浸式音乐播放器迁移实践
华为·harmonyos
行者9620 小时前
Flutter跨平台开发:安全检测组件适配OpenHarmony
flutter·harmonyos·鸿蒙
小雨下雨的雨21 小时前
Flutter 框架跨平台鸿蒙开发 —— GridView 控件之多维网格美学
flutter·华为·交互·harmonyos·鸿蒙系统