目录

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:

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.

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).

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.

@Entry
@Component
struct ProgressCase1 {
  @State progressValue: number = 0;    // Set the initial value of the progress indicator to 0.
  build() {
    Column() {
      Column() {
        Progress({value:this.progressValue, total:100, type:ProgressType.Capsule}).width(200).height(50)
        Row().width('100%').height(5)
        // Replace $r('app.string.progress_add') with the actual resource file. In this sample, the value of the resource file is "progress indicator+5".
        Button($r('app.string.progress_add'))
          .onClick(()=>{
            this.progressValue += 5;
            if (this.progressValue > 100){
              this.progressValue = 0;
            }
          })
      }
    }.width('100%').height('100%')
  }
}