We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All

Progress Indicator (Progress)

The Progress component is used to provide an indicator that shows the progress of an operation. For details, see Progress.

Creating a Progress Indicator

Progress is created by calling an API. The API call method is as follows:

Collapse
Word wrap
Dark theme
Copy code
  1. Progress(options: {value: number, total?: number, type?: ProgressType})

In the API, value is used to set the current progress value, total is used to set the total progress length, and type is used to set the Progress style.

Collapse
Word wrap
Dark theme
Copy code
  1. Progress({ value: 24, total: 100, type: ProgressType.Linear }) // Create a linear progress indicator with a total progress of 100 and a current progress value of 24.

Setting the Progress Indicator Style

Progress provides five types. You can set the progress indicator style through ProgressType. The ProgressType types include: ProgressType.Linear (linear style), ProgressType.Ring (ring style without scale), ProgressType.ScaleRing (ring style with scale), ProgressType.Eclipse (circular style), and ProgressType.Capsule (capsule style).

  • Linear style progress indicator (default type)

    NOTE

    Since API version 9, when the component height is greater than its width, the progress indicator is displayed vertically in an adaptive manner. When the component height equals its width, it remains displayed horizontally.

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. Progress({ value: 20, total: 100, type: ProgressType.Linear }).width(200).height(50)
    2. Progress({ value: 20, total: 100, type: ProgressType.Linear }).width(50).height(200)

  • Ring-style progress indicator without scale marks

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. // From left to right, ring progress indicator No. 1: the default foreground color is a blue gradient, and the default strokeWidth is 4.0 vp.
    2. Progress({ value: 40, total: 150, type: ProgressType.Ring }).width(100).height(100)
    3. // From left to right, ring progress indicator No. 2.
    4. Progress({ value: 40, total: 150, type: ProgressType.Ring }).width(100).height(100)
    5. .color(Color.Grey) // The progress indicator foreground color is gray.
    6. .style({ strokeWidth: 15}) // Set the strokeWidth to 15.0 vp.

  • Ring progress indicator with scale style

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. Progress({ value: 20, total: 150, type: ProgressType.ScaleRing }).width(100).height(100)
    2. .backgroundColor(Color.Black)
    3. .style({ scaleCount: 20, scaleWidth: 5 }) // Set the total scale count of the ring progress bar with scale style to 20 and the scale width to 5 vp.
    4. Progress({ value: 20, total: 150, type: ProgressType.ScaleRing }).width(100).height(100)
    5. .backgroundColor(Color.Black)
    6. .style({ strokeWidth: 15, scaleCount: 20, scaleWidth: 5 }) // Set the ring progress bar with scale style to a width of 15, a total scale count of 20, and a scale width of 5 vp.
    7. Progress({ value: 20, total: 150, type: ProgressType.ScaleRing }).width(100).height(100)
    8. .backgroundColor(Color.Black)
    9. .style({ strokeWidth: 15, scaleCount: 20, scaleWidth: 3 }) // Set the ring progress bar with scale style to a width of 15, a total scale count of 20, and a scale width of 3 vp.

  • Circular style progress indicator

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. // From left to right, circular progress indicator No. 1, with the default foreground color blue.
    2. Progress({ value: 10, total: 150, type: ProgressType.Eclipse }).width(100).height(100)
    3. // From left to right, circular progress indicator No. 2, with the foreground color set to gray.
    4. Progress({ value: 20, total: 150, type: ProgressType.Eclipse }).color(Color.Grey).width(100).height(100)

  • Capsule style progress indicator

    NOTE
    • The progress display at the rounded ends is consistent with the ProgressType.Eclipse style.

    • The progress display in the middle section is a rectangular indicator, similar to the ProgressType.Linear style.

    • When the component height is greater than the width, it automatically adapts to vertical display.

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. Progress({ value: 10, total: 150, type: ProgressType.Capsule }).width(100).height(50)
    2. Progress({ value: 20, total: 150, type: ProgressType.Capsule }).width(50).height(100).color(Color.Grey)
    3. Progress({ value: 50, total: 150, type: ProgressType.Capsule }).width(50).height(100).color(Color.Blue).backgroundColor(Color.Black)

Example

To update the current progress value, for example, in an app installation progress indicator, you can tap the Button to increase progressValue. The value attribute assigns progressValue to the Progress component, which then triggers a refresh and updates the current progress.

Collapse
Word wrap
Dark theme
Copy code
  1. @Entry
  2. @Component
  3. struct ProgressCase1 {
  4. @State progressValue: number = 0; // Set the initial value of the progress indicator to 0.
  5. build() {
  6. Column() {
  7. Column() {
  8. Progress({value:0, total:100, type:ProgressType.Capsule}).width(200).height(50).value(this.progressValue)
  9. Row().width('100%').height(5)
  10. // Replace $r('app.string.progress_add') with the actual resource file. In this sample, the value of the resource file is "progress indicator+5".
  11. Button($r('app.string.progress_add'))
  12. .onClick(()=>{
  13. this.progressValue += 5;
  14. if (this.progressValue > 100){
  15. this.progressValue = 0;
  16. }
  17. })
  18. }
  19. }.width('100%').height('100%')
  20. }
  21. }