HarmonyOS 使用RichEditor 自定义控件不显示

RichEditor(this.options)  
  .onReady(()=>{  
    this.controller.addTextSpan('this.htmlStr',  
      {  
        style:  
        {  
          fontColor: Color.Orange,  
          fontSize: 10  
        }  
      })  
    this.controller.addBuilderSpan(this.rcc(this.htmlStr))  
  })  
  
@Builder  
rcc(str:string){  
  Row(){  
    RichText(str)  
  }  
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
HarmonyOS
2024-09-25 12:42:11
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

addBuilderSpan需传入CustomBuilder类型的参数让自定义组件显示。使用aboutToAppear对初始化CustomBuilder参数,然后调用this.controller.addBuilderSpan()添加需要加入的自定义组件。

@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(str:string){  
    Row(){  
      RichText(str)  
        .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.

另外RichText需要设置一下宽高。

分享
微博
QQ
微信
回复
2024-09-25 18:05:38
相关问题
HarmonyOS 自定义弹窗封装后不显示
1178浏览 • 1回复 待解决
HarmonyOS 自定义时间控件和日期控件
1194浏览 • 1回复 待解决
HarmonyOS 自定义控件实现
930浏览 • 1回复 待解决
HarmonyOS RelativeContainer内的控件不显示
577浏览 • 1回复 待解决
HarmonyOS 自定义Dialog显示问题
1237浏览 • 1回复 待解决
HarmonyOS 自定义弹窗不能显示问题
842浏览 • 1回复 待解决
HarmonyOS 使用自定义字体
976浏览 • 1回复 待解决
HarmonyOS 应用使用iconfont不显示
700浏览 • 1回复 待解决
HarmonyOS 自定义接口如何使用
711浏览 • 1回复 待解决
HarmonyOS 使用全局自定义弹窗
756浏览 • 1回复 待解决
HarmonyOS 自定义组件的使用
763浏览 • 1回复 待解决