鸿蒙ArkTS声明式组件:【Select】

Select

提供下拉选择菜单,可以让用户在多个选项之间选择。

说明:

该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。

子组件

接口

Select(options: Array<[SelectOption]>)

SelectOption对象说明

参数名参数类型必填参数描述
value[ResourceStr]下拉选项内容。
icon[ResourceStr]下拉选项图片。

属性

除支持[通用属性]外,还支持以下属性:

名称参数类型描述
selectednumber[Resource]11+
valuestring[Resource]11+
font[Font]设置下拉按钮本身的文本样式。 默认值: { size: ‘16fp’, weight: FontWeight.Medium }
fontColor[ResourceColor]设置下拉按钮本身的文本颜色。 默认值:‘#E5182431’
selectedOptionBgColor[ResourceColor]设置下拉菜单选中项的背景色。 默认值:‘#33007DFF’
selectedOptionFont[Font]设置下拉菜单选中项的文本样式。 默认值: { size: ‘16fp’, weight: FontWeight.Regular }
selectedOptionFontColor[ResourceColor]设置下拉菜单选中项的文本颜色。 默认值:‘#ff007dff’
optionBgColor[ResourceColor]设置下拉菜单项的背景色。 默认值:‘#ffffffff’
optionFont[Font]设置下拉菜单项的文本样式。 默认值: { size: ‘16fp’, weight: FontWeight.Regular }
optionFontColor[ResourceColor]设置下拉菜单项的文本颜色。 默认值:‘#ff182431’
space10+[Length]设置下拉菜单项的文本与箭头之间的间距。 说明: 不支持设置百分比。
arrowPosition10+[ArrowPosition]设置下拉菜单项的文本与箭头之间的对齐方式。 默认值:ArrowPosition.END
menuAlign10+alignType: [MenuAlignType], offset?: [Offset]设置下拉按钮与下拉菜单间的对齐方式。 -alignType: 对齐方式类型,必填。 默认值:MenuAlignType.START -offset: 按照对齐类型对齐后,下拉菜单相对下拉按钮的偏移量。 默认值:{dx: 0, dy: 0}

ArrowPosition10+枚举说明

名称描述
END10+文字在前,箭头在后。
START10+箭头在前,文字在后。

MenuAlignType10+枚举说明

名称描述
START按照语言方向起始端对齐。
CENTER居中对齐。
END按照语言方向末端对齐。

事件

名称功能描述
onSelect(callback: (index: number, value?: string) => void)下拉菜单选中某一项的回调。 index:选中项的索引。 value:选中项的值。

示例

// xxx.ets
@Entry
@Component
struct SelectExample {
  @State text: string = "TTTTT"
  @State index: number = 2
  @State space: number = 8
  @State arrowPosition: ArrowPosition = ArrowPosition.END
  build() {
    Column() {
      Select([{ value: 'aaa', icon: "/common/public_icon.svg" },
        { value: 'bbb', icon: "/common/public_icon.svg" },
        { value: 'ccc', icon: "/common/public_icon.svg" },
        { value: 'ddd', icon: "/common/public_icon.svg" }])
        .selected(this.index)
        .value(this.text)
        .font({ size: 16, weight: 500 })
        .fontColor('#182431')
        .selectedOptionFont({ size: 16, weight: 400 })
        .optionFont({ size: 16, weight: 400 })
        .space(this.space)
        .arrowPosition(this.arrowPosition)
        .menuAlign(MenuAlignType.START, {dx:0, dy:0})
        .onSelect((index:number, text?: string | undefined)=>{
          console.info('Select:' + index)
          this.index = index;
          if(text){
            this.text = text;
          }
        })
    }.width('100%')
  }
}

在这里插入图片描述

  • 9
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值