HarmonyOS 如何给Text增加描边?

如何给Text增加描边,好像只看到有shadow,outline外描边,没有文本描边的设置

阅读 414
1 个回答

Text组件目前没有描边的属性,可以参考canvas绘制填充和描边重合达到想要的效果

demo:

@Entry
@Component
struct TextExample {
  private settings: RenderingContextSettings = new RenderingContextSettings(true)
  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)

  build() {
    Column() {
      Row() {
        Text("效果:")
          .fontSize(22)
          .fontColor(Color.Blue)
          .maxLines(1)
          .textOverflow({ overflow: TextOverflow.Ellipsis })
          .fontWeight(300)

        Canvas(this.context)
          .width('100%')
          .onReady(() => {
            this.context.font = 'bold 100px sans-serif';
            this.context.fillStyle = '#ff18f608';
            this.context.fillText("Canvas 绘制", 0, 250);

            this.context.font = 'bold 100px sans-serif';
            this.context.lineWidth = 1;
            this.context.strokeStyle = '#fffd0808';
            this.context.strokeText("Canvas 绘制", 0, 250);
          })
      }.width('100%').margin(5)
    }.width('100%')
  }
}