#鸿蒙学习大百科#如何向RichEditor文本框中添加一个@Builder修饰的内容?

如何向RichEditor文本框中添加一个@Builder修饰的内容?

HarmonyOS
2024-10-26 09:29:15
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
海底捞天王
@Entry
@Component
struct Index {
  my_builder: CustomBuilder|undefined = undefined;
  controller: RichEditorController = new RichEditorController();
  options: RichEditorOptions = { controller: this.controller };
  build() {
    Column() {
      RichEditor(this.options)
        .onReady(() => {
          this.controller.addTextSpan('点击按钮在此处添加@Builder', {
            style: {
              fontColor: Color.Black,
              fontSize: 15
            }
          })
        })
        .width(300)
        .height(100)
      Button('addBuilderSpan', {
        buttonStyle: ButtonStyleMode.NORMAL
      })
        .height(30)
        .fontSize(13)
        .onClick(() => {
          this.my_builder = () => {
            this.TextBuilder()
          }
          this.controller.addBuilderSpan(this.my_builder)
        })
    }
    .width('100%')
    .height('100%')
    .justifyContent(FlexAlign.Center)

  }
  @Builder
  TextBuilder() {
    Row() {
      Image($r('app.media.startIcon')).width(50).height(50).margin(16)
      Column() {
        Text("文本文档.txt").fontWeight(FontWeight.Bold).fontSize(16)
        Text("123.45KB").fontColor('#8a8a8a').fontSize(12)
      }.alignItems(HorizontalAlign.Start)
    }.backgroundColor('#f4f4f4')
    .borderRadius("20")
    .width(220)
  }
}
  • 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.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
分享
微博
QQ
微信
回复
2024-10-26 16:37:34
相关问题