HarmonyOS-UIAbitity-Select——【坚果派-红目香薰】
摘要
作者:红目香薰
团队:坚果派 
团队介绍:坚果派由坚果创建,团队拥有12个华为HDE以及若干其他领域的三十余位万粉博主运营。 
Select
提供下拉选择菜单,可以让用户在多个选项之间选择。
接口
Select(options: Array<SelectOption>)
SelectOption对象说明:
| 
 参数名  | 
 参数类型  | 
 必填  | 
 参数描述  | 
|
| 
 value  | 
 ResourceStr  | 
 是  | 
 下拉选项内容。  | 
|
| 
 icon  | 
 ResourceStr  | 
 否  | 
 下拉选项图片。  | 
属性
| 
 名称  | 
 参数类型  | 
 描述  | 
|
| 
 selected  | 
 number  | 
 设置下拉菜单初始选项的索引,第一项的索引为0。  | 
|
| 
 value  | 
 string  | 
 设置下拉按钮本身的文本显示。  | 
|
| 
 font  | 
 Font  | 
 设置下拉按钮本身的文本样式。  | 
|
| 
 fontColor  | 
 ResourceColor  | 
 设置下拉按钮本身的文本颜色。  | 
|
| 
 selectedOptionBgColor  | 
 ResourceColor  | 
 设置下拉菜单选中项的背景色。  | 
|
| 
 selectedOptionFont  | 
 Font  | 
 设置下拉菜单选中项的文本样式。  | 
|
| 
 selectedOptionFontColor  | 
 ResourceColor  | 
 设置下拉菜单选中项的文本颜色。  | 
|
| 
 optionBgColor  | 
 ResourceColor  | 
 设置下拉菜单项的背景色。  | 
|
| 
 optionFont  | 
 Font  | 
 设置下拉菜单项的文本样式。  | 
|
| 
 optionFontColor  | 
 ResourceColor  | 
 设置下拉菜单项的文本颜色。  | 
事件
| 
 名称  | 
 功能描述  | 
| 
 onSelect(callback: (index: number, value?:string) => void)  | 
 下拉菜单选中某一项的回调。index:选中项的索引。value:选中项的值。  | 
代码示例:
@Entry
@Component
struct Index {
  build() {
    Column() {
      Select([{value:'aaa',icon: $r('app.media.icon')},
        {value:'bbb',icon: $r('app.media.2')},
        {value:'ccc',icon: $r('app.media.3')},
        {value:'ddd',icon: $r('app.media.4')}])
        .selected(2)
        .value('TTT')
        .font({size: 30, weight:400, family: 'serif', style: FontStyle.Normal })
        .selectedOptionFont({size: 40, weight: 500, family: 'serif', style: FontStyle.Normal })
        .optionFont({size: 30, weight: 400, family: 'serif', style: FontStyle.Normal })
        .onSelect((index:number)=>{
          console.info("Select:" + index)
        })
    }
  }
}
实际效果:


- 点赞
 - 收藏
 - 关注作者
 
            
           
评论(0)