HarmonyOS Select组件的箭头图标是否可以使用自定义图形?

如题:HarmonyOS Select组件的箭头图标是否可以使用自定义图形?

阅读 520
1 个回答

可以使用浮层覆盖原有箭头图标,示例如下:

@Entry
@Component
struct SelectExample {
  @State text: string = "请选择"
  @State index: number = 2
  @State space: number = 8
  @State arrowPosition: ArrowPosition = ArrowPosition.END
  @Builder OverlayNode() {
    Column() {
      Image($r('app.media.heart_fill'))
    }.width(20).height(20).alignItems(HorizontalAlign.Center)
  }
  @Styles clickedStyles():void {
    .backgroundColor(Color.Transparent)
  }
  build() {
    Column() {
      Select([{ value: 'aaa',  },
        { value: 'bbb',  },
        { value: 'ccc',  },
        { value: 'ddd', }])
        .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})
        .optionWidth(200)
        .optionHeight(300)
        .overlay(this.OverlayNode(), {
          align: Alignment.Bottom,
          offset: { x: -35, y: -10 }
        })
        .stateStyles({
          clicked: this.clickedStyles,
        })
        .arrowPosition(ArrowPosition.START)
        .onSelect((index:number, text?: string | undefined)=>{
          console.info('Select:' + index)
          this.index = index;
          if(text){
            this.text = text;
          }
        })
    }.width('100%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进