W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
可以與容器組件聯(lián)動用于按邏輯結(jié)構(gòu)快速定位容器顯示區(qū)域的組件。
該組件從API Version 7開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨(dú)標(biāo)記該內(nèi)容的起始版本。
AlphabetIndexer(value: {arrayValue: Array<string>, selected: number})
參數(shù):
參數(shù)名 | 參數(shù)類型 | 必填 | 參數(shù)描述 |
---|---|---|---|
arrayValue | Array<string> | 是 | 字母索引字符串?dāng)?shù)組,不可設(shè)置為空。 |
selected | number | 是 | 初始選中項索引值,若超出索引值范圍,則取默認(rèn)值0。 |
除支持通用屬性外,還支持以下屬性:
名稱 | 參數(shù)類型 | 描述 |
---|---|---|
color | 設(shè)置文字顏色。 默認(rèn)值:0x99000000。 | |
selectedColor | 設(shè)置選中項文字顏色。 默認(rèn)值:0xFF254FF7。 | |
popupColor | 設(shè)置提示彈窗文字顏色。 默認(rèn)值:0xFF254FF7。 | |
selectedBackgroundColor | 設(shè)置選中項背景顏色。 默認(rèn)值:0x1F0A59F7。 | |
popupBackground | 設(shè)置提示彈窗背景色。 默認(rèn)值:0xFFFFFFFF。 | |
usingPopup | boolean | 設(shè)置是否使用提示彈窗。 默認(rèn)值:false。 |
selectedFont | 設(shè)置選中項文字樣式。 默認(rèn)值: { size:'12.0fp', style:FontStyle.Normal, weight:FontWeight.Normal, family:'HarmonyOS Sans' } | |
popupFont | 設(shè)置提示彈窗字體樣式。 默認(rèn)值: { size:'24.0vp', style:FontStyle.Normal, weight:FontWeight.Normal, family:'HarmonyOS Sans' } | |
font | 設(shè)置字母索引條默認(rèn)字體樣式。 默認(rèn)值: { size:'12.0fp', style:FontStyle.Normal, weight:FontWeight.Normal, family:'HarmonyOS Sans' } | |
itemSize | string | number | 設(shè)置字母索引條字母區(qū)域大小,字母區(qū)域為正方形,即正方形邊長。不支持設(shè)置為百分比。 默認(rèn)值:24.0 單位:vp |
alignStyle | IndexerAlign | 設(shè)置字母索引條彈框的對齊樣式,支持彈窗顯示在索引條右側(cè)和左側(cè)。 默認(rèn)值:IndexerAlign.Right。 |
selected | number | 設(shè)置選中項索引值。 默認(rèn)值:0。 |
popupPosition | 設(shè)置彈出窗口相對于索引器條上邊框中點(diǎn)的位置。 默認(rèn)值:{x:60.0, y:48.0}。 |
支持通用事件外,還支持以下事件:
名稱 | 功能描述 |
---|---|
onSelected(callback: (index: number) => void)(deprecated) | 索引條選中回調(diào),返回值為當(dāng)前選中索引。 從API Version 8開始廢棄,建議使用onSelect代替。 |
onSelect(callback: (index: number) => void)8+ | 索引條選中回調(diào),返回值為當(dāng)前選中索引。 |
onRequestPopupData(callback: (index: number) => Array<string>)8+ | 選中字母索引后,請求索引提示彈窗顯示內(nèi)容回調(diào)。 返回值:索引對應(yīng)的字符串?dāng)?shù)組,此字符串?dāng)?shù)組在彈窗中豎排顯示,字符串列表最多顯示5個,超出部分可以滑動顯示。 |
onPopupSelect(callback: (index: number) => void)8+ | 字母索引提示彈窗字符串列表選中回調(diào)。 |
- // xxx.ets
- @Entry
- @Component
- struct AlphabetIndexerSample {
- private arrayA: string[] = ['安']
- private arrayB: string[] = ['卜', '白', '包', '畢', '丙']
- private arrayC: string[] = ['曹', '成', '陳', '催']
- private arrayL: string[] = ['劉', '李', '樓', '梁', '雷', '呂', '柳', '盧']
- private value: string[] = ['#', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
- 'H', 'I', 'J', 'K', 'L', 'M', 'N',
- 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
- 'V', 'W', 'X', 'Y', 'Z']
- build() {
- Stack({ alignContent: Alignment.Start }) {
- Row() {
- List({ space: 20, initialIndex: 0 }) {
- ForEach(this.arrayA, (item) => {
- ListItem() {
- Text(item)
- .width('80%')
- .height('5%')
- .fontSize(30)
- .textAlign(TextAlign.Center)
- }.editable(true)
- }, item => item)
- ForEach(this.arrayB, (item) => {
- ListItem() {
- Text(item)
- .width('80%')
- .height('5%')
- .fontSize(30)
- .textAlign(TextAlign.Center)
- }.editable(true)
- }, item => item)
- ForEach(this.arrayC, (item) => {
- ListItem() {
- Text(item)
- .width('80%')
- .height('5%')
- .fontSize(30)
- .textAlign(TextAlign.Center)
- }.editable(true)
- }, item => item)
- ForEach(this.arrayL, (item) => {
- ListItem() {
- Text(item)
- .width('80%')
- .height('5%')
- .fontSize(30)
- .textAlign(TextAlign.Center)
- }.editable(true)
- }, item => item)
- }
- .width('50%')
- .height('100%')
- AlphabetIndexer({ arrayValue: this.value, selected: 0 })
- .selectedColor(0xFFFFFF) // 選中項文本顏色
- .popupColor(0xFFFAF0) // 彈出框文本顏色
- .selectedBackgroundColor(0xCCCCCC) // 選中項背景顏色
- .popupBackground(0xD2B48C) // 彈出框背景顏色
- .usingPopup(true) // 是否顯示彈出框
- .selectedFont({ size: 16, weight: FontWeight.Bolder }) // 選中項字體樣式
- .popupFont({ size: 30, weight: FontWeight.Bolder }) // 彈出框內(nèi)容的字體樣式
- .itemSize(28) // 每一項的尺寸大小
- .alignStyle(IndexerAlign.Left) // 彈出框在索引條右側(cè)彈出
- .onSelect((index: number) => {
- console.info(this.value[index] + ' Selected!')
- })
- .onRequestPopupData((index: number) => {
- if (this.value[index] == 'A') {
- return this.arrayA // 當(dāng)選中A時,彈出框里面的提示文本列表顯示A對應(yīng)的列表arrayA,選中B、C、L時也同樣
- } else if (this.value[index] == 'B') {
- return this.arrayB
- } else if (this.value[index] == 'C') {
- return this.arrayC
- } else if (this.value[index] == 'L') {
- return this.arrayL
- } else {
- return [] // 選中其余子母項時,提示文本列表為空
- }
- })
- .onPopupSelect((index: number) => {
- console.info('onPopupSelected:' + index)
- })
- }
- .width('100%')
- .height('100%')
- }
- }
- }
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: