• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Progress
2
3进度条组件,用于显示内容加载或操作处理等进度。
4
5>  **说明:**
6>
7>  该组件从API version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
8
9
10## 子组件
11
1213
14
15## 接口
16
17Progress(options: {value: number, total?: number, type?: ProgressType})
18
19创建进度组件,用于显示内容加载或操作处理进度。
20
21从API version 9开始,该接口支持在ArkTS卡片中使用。
22
23**参数:**
24
25| 参数名                        | 参数类型                                | 必填   | 参数描述                                     |
26| -------------------------- | ----------------------------------- | ---- | ---------------------------------------- |
27| value                      | number                              | 是    | 指定当前进度值。设置小于0的数值时置为0,设置大于total的数值时置为total。<br/>从API version 9开始,该接口支持在ArkTS卡片中使用。 |
28| total                      | number                              | 否    | 指定进度总长。<br/>默认值:100<br/>从API version 9开始,该接口支持在ArkTS卡片中使用。 |
29| type<sup>8+</sup>          | [ProgressType](#progresstype枚举说明)   | 否    | 指定进度条类型。<br/>默认值:ProgressType.Linear<br/>从API version 9开始,该接口支持在ArkTS卡片中使用。 |
30| style<sup>(deprecated)</sup> | [ProgressStyle](#progressstyle枚举说明) | 否    | 指定进度条样式。<br/>该参数从API version8开始废弃,建议使用type替代。<br/>默认值:ProgressStyle.Linear |
31
32## ProgressType枚举说明
33
34从API version 9开始,该接口支持在ArkTS卡片中使用。
35
36| 名称                     | 描述                                       |
37| ---------------------- | ---------------------------------------- |
38| Linear                 | 线性样式。从API version9开始,高度大于宽度的时候自适应垂直显示。   |
39| Ring<sup>8+</sup>      | 环形无刻度样式,环形圆环逐渐显示至完全填充效果。                 |
40| Eclipse<sup>8+</sup>   | 圆形样式,显示类似月圆月缺的进度展示效果,从月牙逐渐变化至满月。         |
41| ScaleRing<sup>8+</sup> | 环形有刻度样式,显示类似时钟刻度形式的进度展示效果。从API version9开始,刻度外圈出现重叠的时候自动转换为环形无刻度进度条。 |
42| Capsule<sup>8+</sup>   | 胶囊样式,头尾两端圆弧处的进度展示效果与Eclipse相同;中段处的进度展示效果与Linear相同。高度大于宽度的时候自适应垂直显示。 |
43
44##  ProgressStyle枚举说明
45
46从API version 9开始,该接口支持在ArkTS卡片中使用。
47
48| 名称        | 描述                                       |
49| --------- | ---------------------------------------- |
50| Linear    | 线性样式。                                    |
51| Ring      | 环形无刻度样式,环形圆环逐渐显示至完全填充效果。                 |
52| Eclipse   | 圆形样式,显示类似月圆月缺的进度展示效果,从月牙逐渐变化至满月。         |
53| ScaleRing | 环形有刻度样式,显示类似时钟刻度形式的进度展示效果。               |
54| Capsule   | 胶囊样式,头尾两端圆弧处的进度展示效果与Eclipse相同;中段处的进度展示效果与Linear相同。高度大于宽度的时候自适应垂直显示。 |
55
56## 属性
57
58除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性:
59
60| 名称               | 参数类型                                                     | 描述                                                         |
61| ------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
62| value              | number                                                       | 设置当前进度值。设置小于0的数值时置为0,设置大于total的数值时置为total。非法数值不生效。<br/>从API version 9开始,该接口支持在ArkTS卡片中使用。 |
63| color              | [ResourceColor](ts-types.md#resourcecolor)    \| [LinearGradient<sup>10+</sup>](ts-basic-components-datapanel.md#lineargradient10对象说明) | 设置进度条前景色。<br/>从API version 10开始支持利用LinearGradient设置Ring样式的渐变色。<br/>默认值(API version 9):'\#ff007dff'<br/>默认值(API version 10):<br/>- Capsule:'\#33006cde'<br/>- Ring:起始端:'\#ff3b61f7',结束端:'\#ff6591bf'<br/>- 其他样式:'\#ff007dff'<br/>从API version 9开始,该接口支持在ArkTS卡片中使用,暂不支持LinearGradient。 |
64| backgroundColor    | [ResourceColor](ts-types.md#resourcecolor)                   | 设置进度条底色。<br/>默认值(API version 9):'\#19182431'<br/>默认值(API version 10):<br/>- Capsule:'\#33ffffff'<br/>- Ring:'\#08182431'<br/>- 其他样式:'\#19182431'<br/>从API version 9开始,该接口支持在ArkTS卡片中使用。<br/>**说明:** <br/>当设置[通用属性backgroundColor](./ts-universal-attributes-background.md)时,生效的是进度条的底色,而不是整个Progress组件的背景色。 |
65| style<sup>8+</sup> | [ProgressStyleOptions](#progressstyleoptions) \| [CapsuleStyleOptions<sup>10+</sup>](#capsulestyleoptions10) \| [RingStyleOptions<sup>10+</sup>](#ringstyleoptions10) \| [LinearStyleOptions<sup>10+</sup>](#linearstyleoptions10) \| [ScaleRingStyleOptions<sup>10+</sup>](#scaleringstyleoptions10) \| [EclipseStyleOptions<sup>10+</sup>](#eclipsestyleoptions10) | 定义组件的样式。<br/>从API version 10开始支持以下类型:<br/>- CapsuleStyleOptions:设置Capsule的样式。<br/>- RingStyleOptions:设置Ring的样式。<br/>- LinearStyleOptions:设置Linear的样式。<br/>- ScaleRingStyleOptions:设置ScaleRing的样式。<br/>- EclipseStyleOptions:设置Eclipse的样式。<br/>- ProgressStyleOptions:仅可设置各类型进度条的基本样式。<br/>从API version 9开始,该接口支持在ArkTS卡片中设置ProgressStyleOptions,暂不支持其它的参数类型。 |
66
67## ProgressStyleOptions
68| 名称          | 参数类型                      | 必填 | 描述                                                                                        |
69| ------------ | ---------------------------- | ---- | ------------------------------------------------------------------------------------------ |
70| strokeWidth  | [Length](ts-types.md#length) | 否   | 设置进度条宽度(不支持百分比设置)。<br/>默认值:4.0vp                                            |
71| scaleCount   | number                       | 否   | 设置环形进度条总刻度数。<br/>默认值:120                                                        |
72| scaleWidth   | [Length](ts-types.md#length) | 否   | 设置环形进度条刻度粗细(不支持百分比设置),刻度粗细大于进度条宽度时,为系统默认粗细。<br/>默认值:2.0vp |
73| enableSmoothEffect<sup>10+</sup> | boolean | 否 | 进度平滑动效的开关。开启平滑动效后设置进度,进度会从当前值渐变至设定值,否则进度从当前值突变至设定值。<br/>默认值:true |
74
75## CapsuleStyleOptions<sup>10+</sup>
76| 名称          | 参数类型 | 必填 | 描述 |
77| ------------- | ------- | ---- | -------- |
78| borderColor | [ResourceColor](ts-types.md#resourcecolor) | 否 | 内描边颜色。<br/>默认值:'\#33006cde' |
79| borderWidth | [Length](ts-types.md#length) | 否 | 内描边宽度(不支持百分比设置)。<br/>默认值:1vp |
80| content | string | 否 | 文本内容,应用可自定义。 |
81| font | [Font](ts-types.md#font) | 否 | 文本样式。<br/>默认值:<br/>- 文本大小(不支持百分比设置):12fp <br/>其他文本参数跟随text组件的主题值。|
82| fontColor | [ResourceColor](ts-types.md#resourcecolor) | 否 | 文本颜色。<br/>默认值:'\#ff182431' |
83| enableScanEffect | boolean | 否 | 扫光效果的开关。<br/>默认值:false |
84| showDefaultPercentage | boolean | 否 | 显示百分比文本的开关,开启后会在进度条上显示当前进度的百分比。设置了content属性时该属性不生效。<br/>默认值:false |
85| enableSmoothEffect | boolean | 否 | 进度平滑动效的开关。开启平滑动效后设置进度,进度会从当前值渐变至设定值,否则进度从当前值突变至设定值。<br/>默认值:true |
86
87## RingStyleOptions<sup>10+</sup>
88| 名称           | 参数类型                      | 必填 | 描述                                                                                        |
89| ------------- | ---------------------------- | ---- | ------------------------------------------------------------------------------------------ |
90| strokeWidth   | [Length](ts-types.md#length) | 否   | 设置进度条宽度(不支持百分比设置),宽度大于等于半径时,默认修改宽度至半径值的二分之一。<br/>默认值:4.0vp |
91| shadow        | boolean                      | 否   | 进度条阴影开关。<br/>默认值:false                                                             |
92| status        | [ProgressStatus<sup>10+</sup>](#progressstatus10枚举说明) | 否 | 进度条状态,当设置为LOADING时会开启检查更新动效,此时设置进度值不生效。当从LOADING设置为PROGRESSING,检查更新动效会执行到终点再停止。<br/>默认值: ProgressStatus.PROGRESSING |
93| enableScanEffect | boolean | 否 | 进度条扫光效果的开关。<br/>默认值: false |
94| enableSmoothEffect | boolean | 否 | 进度平滑动效的开关。开启平滑动效后设置进度,进度会从当前值渐变至设定值,否则进度从当前值突变至设定值。<br/>默认值:true |
95
96## LinearStyleOptions<sup>10+</sup>
97| 名称           | 参数类型                      | 必填 | 描述                                                                                        |
98| ------------- | ---------------------------- | ---- | ------------------------------------------------------------------------------------------ |
99| strokeWidth   | [Length](ts-types.md#length) | 否   | 设置进度条宽度(不支持百分比设置)。<br/>默认值:4.0vp |
100| strokeRadius   | [PX](ts-types.md#px10)    \| [VP](ts-types.md#vp10)    \| [LPX](ts-types.md#lpx10)    \| [Resource](ts-types.md#resource)| 否   | 设置线性进度条圆角半径。<br/>取值范围[0, strokeWidth / 2]。默认值:strokeWidth / 2。 |
101| enableScanEffect | boolean | 否 | 进度条扫光效果的开关。<br/>默认值: false |
102| enableSmoothEffect | boolean | 否 | 进度平滑动效的开关。开启平滑动效后设置进度,进度会从当前值渐变至设定值,否则进度从当前值突变至设定值。<br/>默认值:true |
103
104## ScaleRingStyleOptions<sup>10+</sup>
105| 名称          | 参数类型                      | 必填 | 描述                                                                                        |
106| ------------ | ---------------------------- | ---- | ------------------------------------------------------------------------------------------ |
107| strokeWidth  | [Length](ts-types.md#length) | 否   | 设置进度条宽度(不支持百分比设置)。<br/>默认值:4.0vp                                            |
108| scaleCount   | number                       | 否   | 设置环形进度条总刻度数。<br/>默认值:120                                                        |
109| scaleWidth   | [Length](ts-types.md#length) | 否   | 设置环形进度条刻度粗细(不支持百分比设置),刻度粗细大于进度条宽度时,为系统默认粗细。<br/>默认值:2.0vp |
110| enableSmoothEffect | boolean | 否 | 进度平滑动效的开关。开启平滑动效后设置进度,进度会从当前值渐变至设定值,否则进度从当前值突变至设定值。<br/>默认值:true |
111
112## EclipseStyleOptions<sup>10+</sup>
113| 名称          | 参数类型                      | 必填 | 描述                                                                                        |
114| ------------ | ---------------------------- | ---- | ------------------------------------------------------------------------------------------ |
115| enableSmoothEffect | boolean | 否 | 进度平滑动效的开关。开启平滑动效后设置进度,进度会从当前值渐变至设定值,否则进度从当前值突变至设定值。<br/>默认值:true |
116
117## ProgressStatus<sup>10+</sup>枚举说明
118| 名称                    | 描述             |
119| ----------------------- | ---------------- |
120| LOADING  | 加载中。 |
121| PROGRESSING | 进度更新中。 |
122
123## 事件
124
125支持[通用事件](ts-universal-events-click.md)。
126
127## 示例
128### 示例1
129各进度条基础属性效果
130```ts
131// xxx.ets
132@Entry
133@Component
134struct ProgressExample {
135  build() {
136    Column({ space: 15 }) {
137      Text('Linear Progress').fontSize(9).fontColor(0xCCCCCC).width('90%')
138      Progress({ value: 10, type: ProgressType.Linear }).width(200)
139      Progress({ value: 20, total: 150, type: ProgressType.Linear }).color(Color.Grey).value(50).width(200)
140
141
142      Text('Eclipse Progress').fontSize(9).fontColor(0xCCCCCC).width('90%')
143      Row({ space: 40 }) {
144        Progress({ value: 10, type: ProgressType.Eclipse }).width(100)
145        Progress({ value: 20, total: 150, type: ProgressType.Eclipse }).color(Color.Grey).value(50).width(100)
146      }
147
148      Text('ScaleRing Progress').fontSize(9).fontColor(0xCCCCCC).width('90%')
149      Row({ space: 40 }) {
150        Progress({ value: 10, type: ProgressType.ScaleRing }).width(100)
151        Progress({ value: 20, total: 150, type: ProgressType.ScaleRing })
152          .color(Color.Grey).value(50).width(100)
153          .style({ strokeWidth: 15, scaleCount: 15, scaleWidth: 5 })
154      }
155
156      // scaleCount和scaleWidth效果对比
157      Row({ space: 40 }) {
158        Progress({ value: 20, total: 150, type: ProgressType.ScaleRing })
159          .color(Color.Grey).value(50).width(100)
160          .style({ strokeWidth: 20, scaleCount: 20, scaleWidth: 5 })
161        Progress({ value: 20, total: 150, type: ProgressType.ScaleRing })
162          .color(Color.Grey).value(50).width(100)
163          .style({ strokeWidth: 20, scaleCount: 30, scaleWidth: 3 })
164      }
165
166      Text('Ring Progress').fontSize(9).fontColor(0xCCCCCC).width('90%')
167      Row({ space: 40 }) {
168        Progress({ value: 10, type: ProgressType.Ring }).width(100)
169        Progress({ value: 20, total: 150, type: ProgressType.Ring })
170          .color(Color.Grey).value(50).width(100)
171          .style({ strokeWidth: 20 })
172      }
173
174      Text('Capsule Progress').fontSize(9).fontColor(0xCCCCCC).width('90%')
175      Row({ space: 40 }) {
176        Progress({ value: 10, type: ProgressType.Capsule }).width(100).height(50)
177        Progress({ value: 20, total: 150, type: ProgressType.Capsule })
178          .color(Color.Grey)
179          .value(50)
180          .width(100)
181          .height(50)
182      }
183    }.width('100%').margin({ top: 30 })
184  }
185}
186```
187
188![progress](figures/arkts-progress.png)
189
190### 示例2
191环形进度条视觉属性
192```ts
193@Entry
194@Component
195struct ProgressExample {
196  private gradientColor: LinearGradient = new LinearGradient([{ color: Color.Yellow, offset: 0.5 },
197                                                              { color: Color.Orange, offset: 1.0 }])
198  build() {
199    Column({ space: 15 }) {
200      Text('Gradient Color').fontSize(9).fontColor(0xCCCCCC).width('90%')
201      Progress({ value: 70, total: 100, type: ProgressType.Ring })
202        .width(100).style({ strokeWidth: 20 })
203        .color(this.gradientColor)
204
205      Text('Shadow').fontSize(9).fontColor(0xCCCCCC).width('90%')
206      Progress({ value: 70, total: 100, type: ProgressType.Ring })
207        .width(120).color(Color.Orange)
208        .style({ strokeWidth: 20, shadow: true })
209    }.width('100%').padding({ top: 5 })
210  }
211}
212```
213![ringProgressStyleEffect](figures/arkts-ringProgressStyleEffect.png)
214
215### 示例3
216环形进度条动效
217```ts
218@Entry
219@Component
220struct ProgressExample {
221  private gradientColor: LinearGradient = new LinearGradient([{ color: Color.Yellow, offset: 0.5 },
222                                                              { color: Color.Orange, offset: 1.0 }])
223  build() {
224    Column({ space: 15 }) {
225      Text('Loading Effect').fontSize(9).fontColor(0xCCCCCC).width('90%')
226      Progress({ value: 0, total: 100, type: ProgressType.Ring })
227        .width(100).color(Color.Blue)
228        .style({ strokeWidth: 20, status: ProgressStatus.LOADING })
229
230      Text('Scan Effect').fontSize(9).fontColor(0xCCCCCC).width('90%')
231      Progress({ value: 30, total: 100, type: ProgressType.Ring })
232        .width(100).color(Color.Orange)
233        .style({ strokeWidth: 20, enableScanEffect: true })
234    }.width('100%').padding({ top: 5 })
235  }
236}
237```
238![ringProgressAnimation](figures/arkts-ringProgressAnimation.gif)
239
240### 示例4
241胶囊形进度条视觉属性
242```ts
243@Entry
244@Component
245struct ProgressExample {
246
247  build() {
248    Column({ space: 15 }) {
249      Row({ space: 40 }) {
250        Progress({ value: 100, total: 100,type: ProgressType.Capsule }).width(100).height(50)
251          .style({borderColor: Color.Blue, borderWidth: 1, content: 'Installing...',
252                  font: {size: 13, style: FontStyle.Normal}, fontColor: Color.Gray,
253                  enableScanEffect: false, showDefaultPercentage: false})
254      }
255    }.width('100%').padding({ top: 5 })
256  }
257}
258```
259![capsuleProgressStyleEffect](figures/arkts-capsuleProgressStyleEffect.png)
260
261### 示例5
262进度平滑动效
263```ts
264@Entry
265@Component
266struct Index {
267  @State value: number = 0
268
269  build() {
270    Column({space: 10}) {
271      Text('enableSmoothEffect: true').fontSize(9).fontColor(0xCCCCCC).width('90%').margin(5)
272        .margin({top: 20})
273      Progress({value: this.value, total: 100, type:ProgressType.Linear})
274        .style({strokeWidth: 10, enableSmoothEffect: true})
275
276      Text('enableSmoothEffect: false').fontSize(9).fontColor(0xCCCCCC).width('90%').margin(5)
277      Progress({value: this.value, total: 100, type:ProgressType.Linear})
278        .style({strokeWidth: 10, enableSmoothEffect: false})
279
280      Button('value +10').onClick(() => {
281        this.value += 10
282      })
283        .width(75)
284        .height(15)
285        .fontSize(9)
286    }
287    .width('50%')
288    .height('100%')
289    .margin({left:20})
290  }
291}
292
293```
294![progressSmoothEffect](figures/arkts-progressSmoothEffect.gif)
295