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)  
  }  
}
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)  
    }  
  }  
}

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

分享
微博
QQ
微信
回复
2024-09-25 18:05:38
相关问题
HarmonyOS 自定义弹窗封装后不显示
1496浏览 • 1回复 待解决
HarmonyOS 自定义控件实现
1256浏览 • 1回复 待解决
HarmonyOS 自定义时间控件和日期控件
1449浏览 • 1回复 待解决
HarmonyOS RelativeContainer内的控件不显示
787浏览 • 1回复 待解决
HarmonyOS 自定义Dialog显示问题
1592浏览 • 1回复 待解决
HarmonyOS 自定义弹窗不能显示问题
1191浏览 • 1回复 待解决
HarmonyOS 使用自定义字体
1214浏览 • 1回复 待解决
HarmonyOS 自定义接口如何使用
922浏览 • 1回复 待解决
HarmonyOS 使用全局自定义弹窗
1030浏览 • 1回复 待解决
HarmonyOS 自定义组件的使用
1140浏览 • 1回复 待解决