目录

What should I do if the text color is overlaid with a layer of transparency after setting the opacity for the Text component?

You can set renderGroup(true) or blendMode(BlendMode.SRC_OVER, BlendApplyType.OFFSCREEN) for the component.

Refer to the code snippet below:

@Entry
@Component
struct Index {
  build() {
    Row() {
      Column() {
        Text('Hello')
          .width(200)
          .height(100)
          .fontColor(Color.White)
          .backgroundColor(Color.Blue)
          .fontSize(20)
          .textAlign(TextAlign.Center)
          .opacity(0.3)
          .margin(20)

        Text('Hello')
          .width(200)
          .height(100)
          .fontColor(Color.White)
          .backgroundColor(Color.Blue)
          .fontSize(20)
          .textAlign(TextAlign.Center)
          .opacity(0.3)
          .renderGroup(true)
      }
      .width('100%')
    }
    .height('100%')
  }
}