鸿蒙(HarmonyOS)下拉选择控件

一、操作环境

操作系统: Windows 11 专业版、IDE:DevEco Studio 3.1.1 Release、SDK:HarmonyOS 3.1.0(API 9)

二、效果图

三、代码

复制代码
SelectPVComponent.ets
TypeScript 复制代码
@Component
export default struct SelectPVComponent {
  @Link selection: SelectOption[]
  private callback: (index: number, value?: string) => void
  private text: string

  build() {
    Row() {
      Image($r('app.media.required')).margin({ bottom: 5 }).width('5%')

      Text(this.text)
      //设置SelectOption对象参数
      Select(this.selection)
        .selected(0)
        .value('请选择')
        .font({ size: 16, weight: 500 })
        .selectedOptionFont({ size: 16, weight: FontWeight.Regular })
        .optionFont({ size: 16, weight: 400 })
        .onSelect((index: number, value: string) => {
          this.callback?.(index, value)
        })
    }.width('100%')
  }
}

在page中的调用方式:

TypeScript 复制代码
//问题程度
//若需要选项前带图标。可自定添加icon:{ value: '一般',icon:'xxx' }
@State issueExtent: SelectOption[] = [{ value: '一般' }, { value: '严重' }, { value: '紧要' }]

build() {
    Column() {
    SelectPVComponent({ text: '问题程度:',
            selection: $issueExtent,
            callback: (index: number, value: string) => {
              console.info('问题程度:' + index + ': ' + value)
            } })
    }
}
相关推荐
未来智慧谷5 小时前
华为发布AI推理新技术,降低对HBM内存依赖
人工智能·华为
幽蓝计划5 小时前
HarmonyOS元服务开发系列教程(三):实现音乐播放和封面旋转
华为·harmonyos
数智顾问5 小时前
【96页PPT】华为IPD流程管理详细版(附下载方式)
华为
挨踢攻城5 小时前
思科、华为、华三如何切换三层端口?
华为·hcie·ccna·hcip·ccnp·cisco·厦门微思网络
zhanshuo6 小时前
HarmonyOS 开发实战:搞定应用名字与图标更换,全流程可运行示例
harmonyos
zhanshuo6 小时前
HarmonyOS 开发实战:快速更改应用名字与图标的终极指南
harmonyos
沉淀风飛8 小时前
鸿蒙Next 性能优化总结
harmonyos
量子位9 小时前
华为诺亚首席研究员,也具身智能创业了
ai编程·harmonyos
旭宇10 小时前
HarmonyOs中使用Navigation路由跳转的完整示例
harmonyos
li理13 小时前
鸿蒙应用本地数据库导出与查看指南
harmonyos