HarmonyOS 是否有区号选择示例

手机号登录需要选择区号,支持右侧按A-Z快速滑动,是否有提供相关示例?

HarmonyOS
2024-12-25 13:06:27
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect
class Contacts {
  constructor(index: string, names: string[]) {
    this.index = index
    this.names = names
  }
  index: string // 序号
  names: string[] // 姓名组
}
@Entry
@Component
struct Index {
  @State contacts: Contacts[] = [
    new Contacts('A', ["xxx", "xxx", "xxx"]),
    new Contacts('B', ["xxx", "xxx", "xxx"]),
    new Contacts('C', ["xxx", "xxx", "xxx"]),
    new Contacts('D', ["xxx", "xxx", "xxx"]),
    new Contacts('E', ["xxx", "xxx"]),
    new Contacts('F', ["xxx", "xxx"]),
    new Contacts('G', ["xxx", "xxx", "xxx"]),
    new Contacts('H', ["xxx", "xxx", "xxx"]),
  ]
  scroller: Scroller = new Scroller() // list 滚动控制
  value: string[] = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
  @State flag: number = 0 // 绑定AlphabetIndexer的index
  preIndex: number = 0;

  build() {
    Row() {
      List({ space: 20, initialIndex: 0, scroller: this.scroller }) {
        ForEach(this.contacts, (value: Contacts) => {
          ListItem() {
            Column() {
              Text('' + value.index)
                .fontSize(30)
                .textAlign(TextAlign.Center)
                .backgroundColor('#ffffff')
                .margin(30)
              ForEach(value.names, (name: string) => {
                Column({ space: 10 }) {
                  Text('' + name)
                    .fontSize(20)
                    .textAlign(TextAlign.Center)
                    .backgroundColor('#ffffff')
                    .margin(10)
                }
              })
            }
          }
        })
      }
      .width('80%')
      .backgroundColor('#fffff0')
      .listDirection(Axis.Vertical)
      .onScrollIndex((firstIndex: number, lastIndex: number) => {
        this.flag = firstIndex // 刷新 AlphabetIndexer
      })
      AlphabetIndexer({ arrayValue: this.value, selected: this.flag })
        .width("20%")
        .font({ size: 20, weight: FontWeight.Bold })
        .selectedColor(Color.Blue)
        .selectedBackgroundColor(0xCCCCCC)
        .usingPopup(true)// 是否显示弹出框
        .selectedFont({ size: 28, weight: FontWeight.Bolder })
        .itemSize(30)
        .alignStyle(IndexerAlign.Left)
        .onSelect((index: number) => {
          console.info(`AlphabetIndexer 选中了 ${this.value[index]}`)
          for (let i = 0; i < this.contacts.length; i++) {
            if (this.contacts[i].index.toString() === this.value[index]) {
              this.preIndex = index;
              this.scroller.scrollToIndex(i);
              return;
            }
          }
          this.flag = this.preIndex;
        })
    }.width("100%")
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
分享
微博
QQ
微信
回复
2024-12-25 15:36:30
相关问题
HarmonyOS 是否navigation示例
477浏览 • 1回复 待解决
HarmonyOS 是否图片滑块验证示例
723浏览 • 1回复 待解决
HarmonyOS 是否个人信息页示例
722浏览 • 1回复 待解决
证书锁定功能示例哪些?
1426浏览 • 1回复 待解决
HarmonyOS 输入框的dialog示例
747浏览 • 1回复 待解决
屏幕自动旋转的示例哪些?
1037浏览 • 1回复 待解决
HarmonyOS 状态选择器吗
701浏览 • 1回复 待解决