代码拉取完成,页面将自动刷新
本示例介绍城市选择场景的使用:通过AlphabetIndexer实现首字母快速定位城市的索引条导航。
使用说明
分两个功能
城市列表中的右侧首拼索引条,通过AlphabetIndexer组件实现首字母快速定位城市的索引条导航。
AlphabetIndexer({ arrayValue: TAB_VALUE, selected: this.stabIndex })
.height('100%')
.selectedColor($r('app.color.citysearch_alphabet_select_color')) // 选中项文本颜色
.popupColor($r('app.color.citysearch_alphabet_pop_color')) // 弹出框文本颜色
.selectedBackgroundColor($r('app.color.citysearch_alphabet_selected_bgc')) // 选中项背景颜色
.popupBackground($r('app.color.citysearch_alphabet_pop_bgc')) // 弹出框背景颜色
.popupPosition({ x: $r('app.integer.citysearch_citysearch_pop_position_x'), y: $r('app.integer.citysearch_citysearch_pop_position_y') })
.usingPopup(true) // 是否显示弹出框
.selectedFont({ size: $r('app.integer.citysearch_select_font'), weight: FontWeight.Bolder }) // 选中项字体样式
.popupFont({ size: $r('app.integer.citysearch_pop_font'), weight: FontWeight.Bolder }) // 弹出框内容的字体样式
.alignStyle(IndexerAlign.Right) // 弹出框在索引条左侧弹出
.onSelect((tabIndex: number) => {
this.scroller.scrollToIndex(tabIndex);
})
List({ space: 14, initialIndex: 0, scroller: this.scroller }) {
.onScrollIndex((firstIndex: number, lastIndex: number) => {
this.stabIndex = firstIndex;
})
}
由于需要通过搜索按钮频繁的控制自定义组件的显隐状态,CityView.ets,因此推荐使用显隐控制替代条件渲染,参考合理选择条件渲染和显隐控制文章。
citysearch // har类型
|---src/main/ets/view
| |---CitySearch.ets // 视图层-主页
| |---CityView.ets // 视图层-城市列表组件
| |---SearchView.ets // 视图层-搜索组件
|---src/main/ets/model
| |---DetailData.ets // 模型层-数据模块
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。