鸿蒙(HarmonyOS)项目方舟框架(ArkUI)之TextPicker组件

鸿蒙(HarmonyOS)项目方舟框架(ArkUI)之TextPicker组件

一、操作环境

操作系统: Windows 10 专业版、IDE:DevEco Studio 3.1、SDK:HarmonyOS 3.1+

二、TextPicker组件

TextClock组件通过文本将当前系统时间显示在设备上。支持不同时区的时间显示,最高精度到秒级。

子组件

无。

接口

TextPicker(options?: {range: string[]|Resource, selected?: number, value?: string})

根据range指定的选择范围创建文本选择器。

构造参数
参数名 参数类型 必填 参数描述
range string[] | Resource 选择器的数据选择列表。
selected number 设置默认选中项在数组中的索引值。 默认值:0
value string 设置默认选中项的值,优先级低于selected。 默认值:第一个元素值
属性

除支持通用属性外,还支持以下属性:

名称 参数类型 描述
defaultPickerItemHeight number | string 设置Picker各选择项的高度。
事件

除支持通用事件外,还支持以下事件:

名称 描述
onAccept(callback: (value: string, index: number) => void) 点击弹窗中的"确定"按钮时触发该回调。 - value: 当前选中项的文本。 - index: 当前选中项的索引值。 说明: 该事件仅在文本滑动选择器弹窗中生效。
onCancel(callback: () => void) 点击弹窗中的"取消"按钮时触发该回调。 说明: 该事件仅在文本滑动选择器弹窗中生效。
onChange(callback: (value: string, index: number) => void) 滑动选中TextPicker文本内容后,触发该回调。 - value: 当前选中项的文本。 - index: 当前选中项的索引值。

三、示例

代码
复制代码
// xxx.ets
@Entry
@Component
struct TextPickerExample {
  private select: number = 1
  private fruits: string[] = ['apple1', 'orange2', 'peach3', 'grape4']

  build() {
    Column() {
      TextPicker({ range: this.fruits, selected: this.select })
        .onChange((value: string, index: number) => {
          console.info('Picker item changed, value: ' + value + ', index: ' + index)
        })
    }
  }
}
图例

你有时间常去我家看看我在这里谢谢你啦...

我家地址:亚丁号

最后送大家一首诗:

山高路远坑深,

大军纵横驰奔,

谁敢横刀立马?

惟有点赞加关注大军。

相关推荐
奔跑的露西ly20 小时前
【HarmonyOS NEXT】Navigation路由导航
华为·harmonyos
pengzhuofan20 小时前
IntelliJ IDEA 常用快捷键
java·ide·intellij-idea
坚果的博客20 小时前
Cordova 开发鸿蒙应用完全指南
华为·harmonyos
Jackson@ML21 小时前
用Visual Studio Code最新版开发C#应用程序
ide·vscode·c#
sonrisa_21 小时前
下载CUDA Toolkit和VS后,配置vscode
ide·vscode·编辑器
无锋起浪1 天前
Vscode参数设置及使用记录ubuntu2204(更新中)
ide·vscode·编辑器
爱笑的眼睛111 天前
HarmonyOS应用开发中HTTP网络请求的封装与拦截器深度实践
华为·harmonyos
通域1 天前
解决启动IDEA后CPU 及内存占用过高配置调整
java·ide·intellij-idea
爱笑的眼睛111 天前
HarmonyOS截屏与录屏API深度解析:从系统权限到像素流处理
华为·harmonyos
zhangfeng11331 天前
医疗智能体(eiHealth) 3.4.0 使用指南(for 华为云Stack 8.5.0) 0. 华为除了这个 还有医疗 和生信方面的 产品
华为·华为云·生物信息