HarmonyOS Text组件是否支持文字描边

Text组件是否支持文字描边?若不支持,是否提供其他绘制文字描边的方式或者Text是否支持自定义绘制。

HarmonyOS
2024-12-25 12:12:59
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
shlp

text组件目前没有描边的属性,可使用canvas绘制填充和描边重合达到想要的效果,参考示例如下:

@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%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
分享
微博
QQ
微信
回复
2024-12-25 15:32:10


相关问题
HarmonyOS Text文本实现
758浏览 • 1回复 待解决
HarmonyOS 如何实现文字效果
1286浏览 • 0回复 待解决
HarmonyOS 如何给Text增加
665浏览 • 1回复 待解决
HarmonyOS svg改变颜色
662浏览 • 1回复 待解决
Text组件是否支持多行显示
2692浏览 • 1回复 待解决
HarmonyOS Text组件如何设置文字方向
628浏览 • 1回复 待解决
Text组件是否支持小图片和表情包
3021浏览 • 1回复 待解决
HarmonyOS 是否支持图片读取文字能力
733浏览 • 1回复 待解决
如何获取Text组件文字的宽度
3110浏览 • 1回复 待解决
HarmonyOS Text组件支持html标签吗
616浏览 • 1回复 待解决