首页
  • GM-3568JHF
  • M4-R1
  • M5-R1
  • SC-3568HA
  • M-K1HSE
  • CF-NRS1
  • CF-CRA2
  • 1684XB-32T
  • 1684X-416T
  • C-3568BQ
  • C-3588LQ
  • GC-3568JBAF
  • C-K1BA
商城
  • English
  • 简体中文
首页
  • GM-3568JHF
  • M4-R1
  • M5-R1
  • SC-3568HA
  • M-K1HSE
  • CF-NRS1
  • CF-CRA2
  • 1684XB-32T
  • 1684X-416T
  • C-3568BQ
  • C-3588LQ
  • GC-3568JBAF
  • C-K1BA
商城
  • English
  • 简体中文
  • M4-R1

    • 一、简介

      • M4-R1简介
    • 二、快速上手

      • 01 OpenHarmony概述
      • 02 镜像烧录
      • 03 应用开发快速上手
      • 04 设备开发快速上手
    • 三、应用开发

      • 01 ArkUI

        • 1 ArkTS语言简介
        • 2 UI 组件-Row 容器介绍
        • 3 UI 组件-Column 容器介绍
        • 4 UI 组件-Text 组件
        • 5 UI 组件-Toggle 组件
        • 6 UI 组件-Slider 组件
        • 7 UI 组件-Animation 组件&Transition 组件
      • 02 资料获取

        • 1 OpenHarmony 官方资料
      • 03 开发须知

        • 1 Full-SDK替换教程
        • 2 引入和使用三方库
        • 3 HDC调试
        • 4 命令行恢复出厂模式
        • 5 升级App为system权限
      • 04 构建第一个应用

        • 1 构建第一个ArkTs应用-HelloWorld
      • 05 案例

        • 01 串口调试助手应用案例
        • 02 手写板应用案例
        • 03 数字时钟应用案例
        • 04 WIFI 信息获取应用案例
    • 四、设备开发

      • 01 环境搭建
      • 02 下载源码
      • 03 编译源码
    • 五、外设与接口

      • 树莓派接口
      • GPIO 接口
      • I2C 接口
      • SPI通信
      • PWM控制
      • 串口通讯
      • TF Card
      • 屏幕
      • 触摸
      • 音频
      • RTC
      • Ethernet
      • M.2
      • MINI-PCIE
      • Camera
      • WIFI&BT
      • 树莓派拓展板
    • 六、资料下载

      • 资料下载
  • M5-R1

    • 一、简介

      • M5-R1简介
    • 二、快速上手

      • 镜像烧录
      • 环境搭建
      • 下载源码
    • 三、外设与接口

      • 树莓派接口
      • GPIO 接口
      • I2C 接口
      • SPI通信
      • PWM控制
      • 串口通讯
      • TF Card
      • 屏幕
      • 触摸
      • 音频
      • RTC
      • Ethernet
      • M.2
      • MINI-PCIE
      • Camera
      • WIFI&BT
    • 四、资料下载

      • 资料下载

6 UI 组件-Slider 组件

滑动条组件,通常用于快速调节设置值的大小,如音量调节、亮度调节等应用场景。

6.1 定义与参数

接口:

Slider(options?: SliderOptions)

参数说明:

  • value:当前滑动值(支持双向绑定)。
  • min/max:滑动条的最大值和最小值。
  • step:滑动步长。
  • 样式:支持OutSet(外置样式)和InSet(内嵌样式)。

6.2 使用示例

// xxx.ets
@Entry
@Component
struct SliderExample {
  @State outSetValueOne: number = 40
  @State inSetValueOne: number = 40
  @State noneValueOne: 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 = 40

  build() {
    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 = value
          console.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 = value
				  console.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 = value
          console.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 = value
          console.info('value:' + value + 'mode:' + mode.toString())
        })
        Text(this.inSetValueTwo.toFixed(0)).fontSize(12)
      }
      .width('80%')

      Text('none slider').fontSize(9).fontColor(0xCCCCCC).width('90%').margin(15)
      Row() {
        Slider({
          value: this.noneValueOne,
          min: 0,
          max: 100,
          style: SliderStyle.NONE
        })
        .blockColor('#191970')
        .trackColor('#ADD8E6')
        .selectedColor('#4169E1')
        .showTips(true)
        .onChange((value: number, mode: SliderChangeMode) => {
          this.noneValueOne = value
          console.info('value:' + value + 'mode:' + mode.toString())
        })
        Text(this.noneValueOne.toFixed(0)).fontSize(12)
      }
      .width('80%')

      Row() {
			  Column() {
			    Text('vertical outset slider').fontSize(9).fontColor(0xCCCCCC).width('50%').margin(15)
			    Row() {
				    Text().width('10%')
            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 = value
              console.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 = value
                  console.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 = value
                console.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 = value
              console.info('value:' + value + 'mode:' + mode.toString())
            })
          }
        }.width('50%').height(300)
      }
    }.width('100%')
  }
}
在 GitHub 上编辑此页
上次更新:
贡献者: jxc
Prev
5 UI 组件-Toggle 组件
Next
7 UI 组件-Animation 组件&Transition 组件