Select
提供下拉選擇菜單,可以讓用戶在多個選項之間選擇。
說明:
開發(fā)前請熟悉鴻蒙開發(fā)指導(dǎo)文檔 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md
]
該組件從API Version 8開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨標(biāo)記該內(nèi)容的起始版本。
子組件
無
接口
Select(options: Array<[SelectOption]>)
SelectOption對象說明
參數(shù)名 | 參數(shù)類型 | 必填 | 參數(shù)描述 |
---|---|---|---|
value | [ResourceStr] | 是 | 下拉選項內(nèi)容。 |
icon | [ResourceStr] | 否 | 下拉選項圖片。 |
屬性
除支持[通用屬性]外,還支持以下屬性:
名稱 | 參數(shù)類型 | 描述 |
---|---|---|
selected | number | [Resource]11+ |
value | string | [Resource]11+ |
font | [Font] | 設(shè)置下拉按鈕本身的文本樣式。 默認(rèn)值: { size: '16fp', weight: FontWeight.Medium } |
fontColor | [ResourceColor] | 設(shè)置下拉按鈕本身的文本顏色。 默認(rèn)值:'#E5182431' |
selectedOptionBgColor | [ResourceColor] | 設(shè)置下拉菜單選中項的背景色。 默認(rèn)值:'#33007DFF' |
selectedOptionFont | [Font] | 設(shè)置下拉菜單選中項的文本樣式。 默認(rèn)值: { size: '16fp', weight: FontWeight.Regular } |
selectedOptionFontColor | [ResourceColor] | 設(shè)置下拉菜單選中項的文本顏色。 默認(rèn)值:'#ff007dff' |
optionBgColor | [ResourceColor] | 設(shè)置下拉菜單項的背景色。 默認(rèn)值:'#ffffffff' |
optionFont | [Font] | 設(shè)置下拉菜單項的文本樣式。 默認(rèn)值: { size: '16fp', weight: FontWeight.Regular } |
optionFontColor | [ResourceColor] | 設(shè)置下拉菜單項的文本顏色。 默認(rèn)值:'#ff182431' |
space10+ | [Length] | 設(shè)置下拉菜單項的文本與箭頭之間的間距。**說明:**不支持設(shè)置百分比。 |
arrowPosition10+ | [ArrowPosition] | 設(shè)置下拉菜單項的文本與箭頭之間的對齊方式。 默認(rèn)值:ArrowPosition.END |
menuAlign10+ | alignType: [MenuAlignType], offset?: [Offset] | 設(shè)置下拉按鈕與下拉菜單間的對齊方式。 -alignType: 對齊方式類型,必填。 默認(rèn)值:MenuAlignType.START -offset: 按照對齊類型對齊后,下拉菜單相對下拉按鈕的偏移量。 默認(rèn)值:{dx: 0, dy: 0} |
ArrowPosition10+枚舉說明
名稱 | 描述 |
---|---|
END10+ | 文字在前,箭頭在后。 |
START10+ | 箭頭在前,文字在后。 |
MenuAlignType10+枚舉說明
名稱 | 描述 |
---|---|
START | 按照語言方向起始端對齊。 |
CENTER | 居中對齊。 |
END | 按照語言方向末端對齊。 |
事件
名稱 | 功能描述 |
---|---|
onSelect(callback: (index: number, value?: string) => void) | 下拉菜單選中某一項的回調(diào)。 index:選中項的索引。 value:選中項的值。HarmonyOS與OpenHarmony鴻蒙文檔籽料:mau123789是v直接拿 |
示例
// 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%')
}
}
審核編輯 黃宇
-
組件
+關(guān)注
關(guān)注
1文章
532瀏覽量
18421 -
鴻蒙
+關(guān)注
關(guān)注
60文章
2620瀏覽量
44046
發(fā)布評論請先 登錄
HarmonyOS/OpenHarmony應(yīng)用開發(fā)-ArkTS的聲明式開發(fā)范式
鴻蒙ArkTS聲明式組件:PatternLock

評論