完整示例参考如下:
@Entry
@Component
struct Linear {
build() {
Column() {
Column() {
Text('顶部渐变')
.textAlign(TextAlign.Center)
.fontSize(40)
.width('100%')
}
.backgroundColor('#F08080')
.expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
.linearGradient({
// 实现从左到右,默认为垂直。90°为水平
angle: 90,
colors: [[0x8981F4, 0.0], [0x86C4E3, 0.3], [0x63CEBF, 1.0]]
})
}
.width('100%')
.height('100%')
}
}