You can use the if/else conditional rendering to achieve the purpose. The code snippet is as follows:
@Entry
@Component
struct TestHeightPage {
@State message: string = 'Hello World';
@State myHeight1: number = 30;
@State myHeight2: number = 60;
@State flag: boolean = false
build() {
Column() {
Text(this.message)
.fontSize(20)
.fontWeight(FontWeight.Bold)
.width('100%')
.height(this.flag ? this.myHeight1 : this.myHeight2)
.backgroundColor(Color.Orange)
Button('Modify Text attribute height').onClick(() => {
this.flag = !this.flag;
}).margin({ top: 12 })
}
.height('100%')
}
} Reference