HarmonyOS Text组件里的文本内容设置渐变色?

产品需求里要求部分文字需要设置成渐变色,目前针对Text组件设置渐变色的时候,只能对组件的背景进行设置,还无法直接针对文字设置渐变色。

阅读 593
1 个回答

可参考如下demo

@Entry
@Component
struct Page11111 {
  @State message: string = 'Hello World';

  build() {
    Row() {
      Text(this.message)
        .fontSize(50)
        .fontWeight(FontWeight.Bold)
        .blendMode(BlendMode.DST_IN, BlendApplyType.OFFSCREEN)
    }
    .linearGradient({
      direction: GradientDirection.Right,
      colors: [[0xff0000, 0.0], [0x0000ff, 0.3], [0xffff00, 1.0]]
    })
    .blendMode(BlendMode.SRC_OVER, BlendApplyType.OFFSCREEN)
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进