文档管理中心
您当前正在浏览HarmonyOS最新文档,覆盖已发布的所有API版本,可在API参考中筛选您使用的API版本。详细的版本配套关系请参考版本说明
API参考应用框架ArkUI(方舟UI框架)ArkTS组件信息展示LoadingProgress

LoadingProgress

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

LoadingProgress是用于显示加载进度条的组件,在数据加载过程中为用户提供视觉反馈,提升用户体验。该组件支持设置前景色、控制动画显示状态等特性,适用于需要在应用内展示加载进度的场景。

加载进度条的动效在组件不可见时停止,组件的可见状态基于onVisibleAreaChange处理,可见阈值ratios大于0即视为可见状态。

说明
  • 该组件从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

  • 该组件从API版本26.0.0开始支持WithTheme

子组件

接口

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

LoadingProgress()

创建加载进度组件。

卡片能力: 从API version 9开始,该接口支持在ArkTS卡片中使用。

元服务API: 从API version 11开始,该接口支持在元服务中使用。

系统能力: SystemCapability.ArkUI.ArkUI.Full

属性

除支持通用属性外,还支持以下属性:

说明

组件应设置合理的宽高,当组件宽高设置过大时加载进度条的动效可能不符合预期效果。

color

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

color(value: ResourceColor)

设置加载进度条前景色。

卡片能力: 从API version 9开始,该接口支持在ArkTS卡片中使用。

元服务API: 从API version 11开始,该接口支持在元服务中使用。

系统能力: SystemCapability.ArkUI.ArkUI.Full

参数:

展开
参数名 类型 必填 说明
value ResourceColor

加载进度条的前景色。

默认值:

API version 10及以下:'#99666666'

API version 11及以上:'#ff666666'

enableLoading10+

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

enableLoading(value: boolean)

设置LoadingProgress动画是否显示。LoadingProgress动画不显示时,该组件依旧占位。通用属性Visibility.Hidden隐藏的是包括borderpadding等整个组件范围,而enableLoading=false只隐藏LoadingProgress本身动画内容,不包括border等。

元服务API: 从API version 11开始,该接口支持在元服务中使用。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.ArkUI.ArkUI.Full

参数:

展开
参数名 类型 必填 说明
value boolean

LoadingProgress动画是否显示。

默认值:true,true表示显示LoadingProgress动画,false表示不显示LoadingProgress动画。

contentModifier12+

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

contentModifier(modifier: ContentModifier<LoadingProgressConfiguration>)

定制LoadingProgress内容区的方法。

元服务API: 从API version 12开始,该接口支持在元服务中使用。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.ArkUI.ArkUI.Full

参数:

展开
参数名 类型 必填 说明
modifier ContentModifier<LoadingProgressConfiguration>

在LoadingProgress组件上,定制内容区的方法。

modifier:内容修改器,开发者需要自定义class实现ContentModifier接口。

事件

支持通用事件

LoadingProgressConfiguration12+对象说明

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

开发者需要自定义class实现ContentModifier接口。继承自CommonConfiguration

元服务API: 从API version 12开始,该接口支持在元服务中使用。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.ArkUI.ArkUI.Full

展开
名称 类型 只读 可选 说明
enableLoading boolean

LoadingProgress动画是否显示。

默认值:true,true表示显示LoadingProgress动画,false表示不显示LoadingProgress动画。

LoadingProgressStyle枚举说明

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

表示LoadingProgress的样式类型,不推荐使用。

卡片能力: 从API version 9开始,该接口支持在ArkTS卡片中使用。

元服务API: 从API version 11开始,该接口支持在元服务中使用。

系统能力: SystemCapability.ArkUI.ArkUI.Full

展开
名称 说明
Default 1 默认加载样式。API version 8及以后不支持设置。
Circular 2 环形加载样式。API version 8及以后不支持设置。
Orbital 3 彗星形加载样式。API version 8及以后默认为彗星形样式。

示例

示例1(设置颜色)

该示例通过color接口,实现了设置加载进度条颜色的功能。

收起
自动换行
深色代码主题
复制
  1. // xxx.ets
  2. @Entry
  3. @Component
  4. struct LoadingProgressExample {
  5. build() {
  6. Column({ space: 5 }) {
  7. Text('Orbital LoadingProgress ').fontSize(9).fontColor(0xCCCCCC).width('90%')
  8. LoadingProgress()
  9. .color(Color.Blue)
  10. .layoutWeight(1)
  11. }.width('100%').margin({ top: 5 })
  12. }
  13. }

示例2(设置定制内容区)

该示例通过contentModifier接口,实现了定制内容区的功能,并展示了如何基于LoadingProgressConfigurationenableLoading属性切换自定义内容的显示效果。

收起
自动换行
深色代码主题
复制
  1. // xxx.ets
  2. import { UIContext } from '@kit.ArkUI';
  3. class MyLoadingProgressStyle implements ContentModifier<LoadingProgressConfiguration> {
  4. enableLoading: boolean = false;
  5. ctx: UIContext | undefined = undefined;
  6. constructor(enableLoading: boolean, ctx: UIContext) {
  7. this.enableLoading = enableLoading;
  8. this.ctx = ctx;
  9. }
  10. applyContent(): WrappedBuilder<[LoadingProgressConfiguration]> {
  11. return wrapBuilder(buildLoadingProgress);
  12. }
  13. }
  14. let arr: string[] = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
  15. @Builder
  16. function buildLoadingProgress(config: LoadingProgressConfiguration) {
  17. Column({ space: 8 }) {
  18. Row() {
  19. Column() {
  20. Circle({
  21. width: ((config.contentModifier as MyLoadingProgressStyle).enableLoading) ? 100 : 80,
  22. height: ((config.contentModifier as MyLoadingProgressStyle).enableLoading) ? 100 : 80
  23. })
  24. .fill(((config.contentModifier as MyLoadingProgressStyle).enableLoading) ? Color.Grey : 0x2577e3)
  25. }.width('50%')
  26. Column() {
  27. Button('' + ((config.contentModifier as MyLoadingProgressStyle).enableLoading))
  28. .onClick((event: ClickEvent) => {
  29. let uiContext = (config.contentModifier as MyLoadingProgressStyle).ctx;
  30. if (uiContext) {
  31. uiContext.getPromptAction().showToast({
  32. message: ((config.contentModifier as MyLoadingProgressStyle).enableLoading) + ''
  33. });
  34. }
  35. })
  36. .fontColor(Color.White)
  37. .backgroundColor(((config.contentModifier as MyLoadingProgressStyle).enableLoading) ? Color.Grey : 0x2577e3)
  38. }.width('50%')
  39. }
  40. Row() {
  41. Column() {
  42. Gauge({
  43. value: (config.contentModifier as MyLoadingProgressStyle).enableLoading ? 50 : 30, min: 11, max: 100
  44. }) {
  45. Column() {
  46. Text('60')
  47. .maxFontSize('180sp')
  48. .minFontSize('160.0vp')
  49. .fontWeight(FontWeight.Medium)
  50. .fontColor('#ff182431')
  51. .width('40%')
  52. .height('30%')
  53. .textAlign(TextAlign.Center)
  54. .margin({ top: '22.2%' })
  55. .textOverflow({ overflow: TextOverflow.Ellipsis })
  56. .maxLines(1)
  57. }.width('100%').height('100%')
  58. }
  59. .colors(((config.contentModifier as MyLoadingProgressStyle).enableLoading) ? Color.Grey : 0x2577e3)
  60. .width(200)
  61. .strokeWidth(18)
  62. .padding(5)
  63. .trackShadow({ radius: 7, offsetX: 7, offsetY: 7 })
  64. .height(200)
  65. }.width('100%')
  66. }
  67. Column() {
  68. List({ space: 20, initialIndex: 0 }) {
  69. ForEach(arr, (item: string) => {
  70. ListItem() {
  71. Text((config.contentModifier as MyLoadingProgressStyle).enableLoading ? '' + item : Number(item) * 2 + '')
  72. .width('100%')
  73. .height('100%')
  74. .fontColor((config.contentModifier as MyLoadingProgressStyle).enableLoading ? Color.White : Color.Orange)
  75. .fontSize((config.contentModifier as MyLoadingProgressStyle).enableLoading ? 16 : 20)
  76. .textAlign(TextAlign.Center)
  77. .backgroundColor((config.contentModifier as MyLoadingProgressStyle).enableLoading ? Color.Grey : 0x2577e3)
  78. }
  79. .height(110)
  80. .border({
  81. width: 2,
  82. color: Color.White
  83. })
  84. }, (item: string) => item)
  85. }
  86. .height(200)
  87. .width('100%')
  88. .friction(0.6)
  89. .lanes({
  90. minLength: (config.contentModifier as MyLoadingProgressStyle).enableLoading ? 40 : 80,
  91. maxLength: (config.contentModifier as MyLoadingProgressStyle).enableLoading ? 40 : 80
  92. })
  93. .scrollBar(BarState.Off)
  94. }
  95. }.width('100%').padding(10)
  96. }
  97. @Entry
  98. @Component
  99. struct LoadingProgressDemoExample {
  100. @State loadingProgressList: (boolean | undefined | null)[] = [undefined, true, null, false];
  101. @State loadingProgressIndex: number = 0;
  102. scroller: Scroller = new Scroller();
  103. build() {
  104. Column() {
  105. Scroll(this.scroller) {
  106. Column({ space: 5 }) {
  107. Column() {
  108. LoadingProgress()
  109. .color('#106836')
  110. .size({ width: '100%' })
  111. .contentModifier(new MyLoadingProgressStyle(this.loadingProgressList[this.loadingProgressIndex], this.getUIContext()))
  112. }.width('100%').backgroundColor(0xdcdcdc)
  113. }.width('100%').margin({ top: 5 })
  114. }.height('85%')
  115. Button('点击切换config.enableLoading').onClick(() => {
  116. this.loadingProgressIndex = (this.loadingProgressIndex + 1) % this.loadingProgressList.length;
  117. console.info('enableLoading:' + this.loadingProgressList[this.loadingProgressIndex]);
  118. }).margin(20)
  119. }
  120. }
  121. }

在 API参考 中进行搜索
请输入您想要搜索的关键词