W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
提供下拉選擇菜單,可以讓用戶在多個選項之間選擇。
該組件從API Version 8開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨標(biāo)記該內(nèi)容的起始版本。
除支持通用屬性外,還支持以下屬性:
名稱 | 參數(shù)類型 | 描述 |
---|---|---|
selected | number | 設(shè)置下拉菜單初始選項的索引,第一項的索引為0。 當(dāng)不設(shè)置selected屬性時,默認(rèn)選擇值為-1,菜單項不選中。 |
value | string | 設(shè)置下拉按鈕本身的文本內(nèi)容。 當(dāng)菜單選中時默認(rèn)會替換為菜單項文本內(nèi)容。 |
font | 設(shè)置下拉按鈕本身的文本樣式。 默認(rèn)值: { size: '16fp', weight: FontWeight.Medium } | |
fontColor | 設(shè)置下拉按鈕本身的文本顏色。 默認(rèn)值:'#E6FFFFFF' | |
selectedOptionBgColor | 設(shè)置下拉菜單選中項的背景色。 默認(rèn)值:'#33007DFF' | |
selectedOptionFont | 設(shè)置下拉菜單選中項的文本樣式。 默認(rèn)值: { size: '16fp', weight: FontWeight.Regular } | |
selectedOptionFontColor | 設(shè)置下拉菜單選中項的文本顏色。 默認(rèn)值:'#ff007dff' | |
optionBgColor | 設(shè)置下拉菜單項的背景色。 默認(rèn)值:'#ffffffff' | |
optionFont | 設(shè)置下拉菜單項的文本樣式。 默認(rèn)值: { size: '16fp', weight: FontWeight.Regular } | |
optionFontColor | 設(shè)置下拉菜單項的文本顏色。 默認(rèn)值:'#ff182431' |
名稱 | 功能描述 |
---|---|
onSelect(callback: (index: number, value?: string) => void) | 下拉菜單選中某一項的回調(diào)。 index:選中項的索引。 value:選中項的值。 |
- // xxx.ets
- @Entry
- @Component
- struct SelectExample {
- 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(2)
- .value('TTTTT')
- .font({ size: 16, weight: 500 })
- .fontColor('#182431')
- .selectedOptionFont({ size: 16, weight: 400 })
- .optionFont({ size: 16, weight: 400 })
- .onSelect((index: number) => {
- console.info('Select:' + index)
- })
- }.width('100%')
- }
- }
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: