#鸿蒙通关秘籍#富文本控件RichText,如何实现Text控件中的Span拼接功能,且能给每个Span增加点击事件?

HarmonyOS
2024-12-11 09:48:19
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
青石巷陌CLI

这个功能的应用场景还是比较多的,代码直接给露出贴出来好了

@Entry
@Component
struct Index {
  @State message: string = 'Hello World';
  controller: RichEditorController = new RichEditorController();
  options: RichEditorOptions = { controller: this.controller };
  private my_builder: CustomBuilder = undefined;

  aboutToAppear(): void {
    this.my_builder = () => {
      this.rcc();
    };
  }

  build() {
    Column() {
      RichEditor(this.options)
        .onReady(() => {
          this.controller.addTextSpan('this.htmlStr', {
            style: {
              fontColor: Color.Orange,
              fontSize: 10
            }
          });
          this.controller.addBuilderSpan(this.my_builder);
        });
    }
  }
}

@Builder
rcc() {
  Row() {
    RichText(`<h1>我是RichText<h1>`)
      .backgroundColor(Color.Orange)
      .width(100)
      .height(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.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
分享
微博
QQ
微信
回复
2024-12-11 12:03:32


相关问题
HarmonyOS如何增加控件点击热区?
1073浏览 • 1回复 待解决
HarmonyOS 文本点击事件
1351浏览 • 1回复 待解决
HarmonyOS TextSpan显示问题
983浏览 • 1回复 待解决
HarmonyOS TextImageSpan和Span
1083浏览 • 1回复 待解决
HarmonyOS web控件加载文本,字太小
1335浏览 • 1回复 待解决
HarmonyOS Text/Span使用问题
868浏览 • 1回复 待解决
HarmonyOS 控件点击事件无响应
581浏览 • 1回复 待解决
HarmonyOS Textspan不能设置间距吗
472浏览 • 1回复 待解决