ProgressButton默认不支持高度调整,如何实现可调高度的下载按钮?
Progress:进度条组件,用于显示内容加载或操作处理等进度。
- Progress({ value: this.progressIndex, total: 100, type: ProgressType.Capsule })
- .width(300)
- .height(100) // 设置Progress组件的高度
- .color(Color.Blue)
- .margin({top:300})
- .style({
- borderWidth: 1,
- content: this.textState, // 设置按钮文字
- font: { size: 13, style: FontStyle.Normal },
- enableScanEffect: false,
- showDefaultPercentage: false
- })
- .onClick(() => {
- this.isRunning = !this.isRunning;
- if (this.textState && !this.isRunning && this.progressIndex < 100) {
- this.textState = '继续';
- }
- let timer = setInterval(() => {
- if (this.isRunning && this.progressIndex < 100) {
- this.progressIndex++;
- this.textState = `${this.progressIndex}%`;
- if (this.progressIndex === 100) {
- this.textState = '已完成';
- this.isRunning = false;
- }
- } else {
- clearInterval(timer);
- }
- }, 20);
- })
- Progress({ value: this.progressIndex, total: 100, type: ProgressType.Capsule })
- .width(300)
- .height(100) // 设置Progress组件的高度
- @Entry
- @Component
- struct PushButton {
- @State progressIndex: number = 0;
- @State textState: string = '下载';
- @State isRunning: boolean = false;
-
- build() {
- Column({ space: 20 }) {
- Progress({ value: this.progressIndex, total: 100, type: ProgressType.Capsule })
- .width(300)
- .height(100) // 设置Progress组件的高度
- .color(Color.Blue)
- .margin({top:300})
- .style({
- borderWidth: 1,
- content: this.textState, // 设置按钮文字
- font: { size: 13, style: FontStyle.Normal },
- enableScanEffect: false,
- showDefaultPercentage: false
- })
-
- .onClick(() => {
- this.isRunning = !this.isRunning;
- if (this.textState && !this.isRunning && this.progressIndex < 100) {
- this.textState = '继续';
- }
- let timer = setInterval(() => {
- if (this.isRunning && this.progressIndex < 100) {
- this.progressIndex++;
- this.textState = `${this.progressIndex}%`;
- if (this.progressIndex === 100) {
- this.textState = '已完成';
- this.isRunning = false;
- }
- } else {
- clearInterval(timer);
- }
- }, 20);
- })
- }.alignItems(HorizontalAlign.Center).width('100%').margin({ top: 20 })
- }
- }