当前位置: 首页 > news >正文

HarmonyOS/OpenHarmony原生应用-ArkTS万能卡片组件Slider

滑动条组件,通常用于快速调节设置值,如音量调节、亮度调节等应用场景。该组件从API Version 7开始支持。无子组件
一、接口
Slider(options?: {value?: number, min?: number, max?: number, step?: number, style?: SliderStyle, direction?: Axis, reverse?: boolean})
从API version 9开始,该接口支持在ArkTS卡片中使用。
参数:
 

HarmonyOS/OpenHarmony原生应用-ArkTS万能卡片组件Slider-开源基础软件社区


 

HarmonyOS/OpenHarmony原生应用-ArkTS万能卡片组件Slider-开源基础软件社区


SliderStyle枚举说明
从API version 9开始,该接口支持在ArkTS卡片中使用。
 

HarmonyOS/OpenHarmony原生应用-ArkTS万能卡片组件Slider-开源基础软件社区


二、属性
支持除触摸热区以外的通用属性设置。
 

HarmonyOS/OpenHarmony原生应用-ArkTS万能卡片组件Slider-开源基础软件社区


 

HarmonyOS/OpenHarmony原生应用-ArkTS万能卡片组件Slider-开源基础软件社区


三、事件
通用事件仅支持挂载卸载事件:OnAppear,OnDisAppear。
 

HarmonyOS/OpenHarmony原生应用-ArkTS万能卡片组件Slider-开源基础软件社区


SliderChangeMode枚举说明
从API version 9开始,该接口支持在ArkTS卡片中使用。
 

HarmonyOS/OpenHarmony原生应用-ArkTS万能卡片组件Slider-开源基础软件社区


四、示例

// xxx.ets
@Entry
@Component
struct SliderExample {@State outSetValueOne: number = 40@State inSetValueOne: number = 40@State outSetValueTwo: number = 40@State inSetValueTwo: number = 40@State vOutSetValueOne: number = 40@State vInSetValueOne: number = 40@State vOutSetValueTwo: number = 40@State vInSetValueTwo: number = 40build() {Column({ space: 8 }) {Text('outset slider').fontSize(9).fontColor(0xCCCCCC).width('90%').margin(15)Row() {Slider({value: this.outSetValueOne,min: 0,max: 100,style: SliderStyle.OutSet}).showTips(true).onChange((value: number, mode: SliderChangeMode) => {this.outSetValueOne = valueconsole.info('value:' + value + 'mode:' + mode.toString())})// toFixed(0)将滑动条返回值处理为整数精度Text(this.outSetValueOne.toFixed(0)).fontSize(12)}.width('80%')Row() {Slider({value: this.outSetValueTwo,step: 10,style: SliderStyle.OutSet}).showSteps(true).onChange((value: number, mode: SliderChangeMode) => {this.outSetValueTwo = valueconsole.info('value:' + value + 'mode:' + mode.toString())})Text(this.outSetValueTwo.toFixed(0)).fontSize(12)}.width('80%')Text('inset slider').fontSize(9).fontColor(0xCCCCCC).width('90%').margin(15)Row() {Slider({value: this.inSetValueOne,min: 0,max: 100,style: SliderStyle.InSet}).blockColor('#191970').trackColor('#ADD8E6').selectedColor('#4169E1').showTips(true).onChange((value: number, mode: SliderChangeMode) => {this.inSetValueOne = valueconsole.info('value:' + value + 'mode:' + mode.toString())})Text(this.inSetValueOne.toFixed(0)).fontSize(12)}.width('80%')Row() {Slider({value: this.inSetValueTwo,step: 10,style: SliderStyle.InSet}).blockColor('#191970').trackColor('#ADD8E6').selectedColor('#4169E1').showSteps(true).onChange((value: number, mode: SliderChangeMode) => {this.inSetValueTwo = valueconsole.info('value:' + value + 'mode:' + mode.toString())})Text(this.inSetValueTwo.toFixed(0)).fontSize(12)}.width('80%')Row() {Column() {Text('vertical outset slider').fontSize(9).fontColor(0xCCCCCC).width('50%').margin(15)Row() {Slider({value: this.vOutSetValueOne,style: SliderStyle.OutSet,direction: Axis.Vertical}).blockColor('#191970').trackColor('#ADD8E6').selectedColor('#4169E1').showTips(true).onChange((value: number, mode: SliderChangeMode) => {this.vOutSetValueOne = valueconsole.info('value:' + value + 'mode:' + mode.toString())})Slider({value: this.vOutSetValueTwo,step: 10,style: SliderStyle.OutSet,direction: Axis.Vertical}).blockColor('#191970').trackColor('#ADD8E6').selectedColor('#4169E1').showSteps(true).onChange((value: number, mode: SliderChangeMode) => {this.vOutSetValueTwo = valueconsole.info('value:' + value + 'mode:' + mode.toString())})}}.width('50%').height(300)Column() {Text('vertical inset slider').fontSize(9).fontColor(0xCCCCCC).width('50%').margin(15)Row() {Slider({value: this.vInSetValueOne,style: SliderStyle.InSet,direction: Axis.Vertical,reverse: true // 竖向的Slider默认是上端是min值,下端是max值,因此想要从下往上滑动,需要设置reverse为true}).showTips(true).onChange((value: number, mode: SliderChangeMode) => {this.vInSetValueOne = valueconsole.info('value:' + value + 'mode:' + mode.toString())})Slider({value: this.vInSetValueTwo,step: 10,style: SliderStyle.InSet,direction: Axis.Vertical,reverse: true}).showSteps(true).onChange((value: number, mode: SliderChangeMode) => {this.vInSetValueTwo = valueconsole.info('value:' + value + 'mode:' + mode.toString())})}}.width('50%').height(300)}}.width('100%')}
}

五、效果样式

HarmonyOS/OpenHarmony原生应用-ArkTS万能卡片组件Slider-开源基础软件社区

六、场景
适合卡片上直接操作提示滑动条组件,通常用于快速调节设置值,如音量调节、亮度调节等应用场景提供。

本文根据HarmonyOS官方文档整理

http://www.lryc.cn/news/197787.html

相关文章:

  • SpringCloud: sentinel链路限流
  • UML 中的关系
  • ChatGPT技术或加剧钓鱼邮件攻击
  • 哨兵1号后向散射系数土壤水分反演
  • day3:Node.js 基础知识
  • 【RDMA】librdmacm库和连接建立过程
  • 如何使用Python抓取PDF文件并自动下载到本地
  • 人脸写真FaceChain的简单部署记录(一)
  • linux虚机新增加磁盘后在系统中查不到
  • js中隐式类型转换与toPrimitive
  • 家政系统预约小程序具备哪些功能?
  • 【LeetCode】46. 全排列
  • 宏电股份RedCap产品亮相迪拜华为MBBF,并参与RedCap全球商用阶段性成果发布
  • Harris图像角点检测
  • 互联网Java工程师面试题·Java 总结篇·第七弹
  • UVa658 It’s not a Bug, it’s a Feature!(Dijkstra)
  • Object 类常用方法
  • chromium 52 chrome 各个版本发布功能列表(58-84)
  • python web开发(四): Bootstrap
  • 【EI会议征稿】2024年遥感技术与测量测绘国际学术会议(RSTSM 2024)
  • 灵感:VUE2实现权限按钮控制
  • 【2023最新版】Python全栈知识点总结
  • 推荐系统离线评估方法和评估指标,以及在推荐服务器内部实现A/B测试和解决A/B测试资源紧张的方法。还介绍了如何在TensorFlow中进行模型离线评估实践。
  • day1:Node.js 简介
  • ESP RainMaker 客户案例 #1|Halonix
  • 【Linux】adduser命令使用
  • 中文连续视觉语音识别挑战赛
  • (ubuntu) 安装JDK
  • 工程管理系统源码之全面+高效的工程项目管理软件
  • 网络安全常见问题隐患及其应对措施