#鸿蒙学习大百科#如何通过TextStyle实现一段丰富的文字?

如何通过TextStyle实现一段丰富的文字?

HarmonyOS
2024-10-26 09:47:31
722浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
自封的不算
import { LengthMetrics } from '@kit.ArkUI';

@Entry
@Component
struct Index {
  textStyleAttrs: TextStyle = new TextStyle({ fontWeight: FontWeight.Bolder, fontSize: LengthMetrics.vp(24), fontStyle: FontStyle.Italic })
  mutableStyledString: MutableStyledString = new MutableStyledString("运动35分钟 目标达成", [
    {
      start: 2,
      length: 2,
      styledKey: StyledStringKey.FONT,
      styledValue: this.textStyleAttrs
    },
    {
      start: 7,
      length: 4,
      styledKey: StyledStringKey.FONT,
      styledValue: new TextStyle({ fontColor: Color.Orange, fontSize: LengthMetrics.vp(12)})
    }
  ]);
  controller: TextController = new TextController();
  onPageShow(): void {
    this.controller.setStyledString(this.mutableStyledString)
  }
  build() {
    Column() {
      // 显示属性字符串
      Text(undefined, { controller: this.controller })
        .margin({ top: 10 })
    }
    .width('100%')
    .height('100%')
    .justifyContent(FlexAlign.Center)

  }
}
  • 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.
  • 33.
  • 34.
  • 35.
  • 36.
分享
微博
QQ
微信
回复
2024-10-26 16:49:12
相关问题
如何实现RSA公钥PK加密一段文字
1292浏览 • 1回复 待解决
#鸿蒙学习大百科#如何实现ui优化?
1012浏览 • 1回复 待解决