HarmonyOS 有没有同时支持富文本和字体大小自适应的组件?

HarmonyOS 有没有同时支持富文本和字体大小自适应的组件?

HarmonyOS
2024-10-11 11:42:30
922浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

可使用三方库@ohos/textlayoutbuilder,链接:https://ohpm.openharmony.cn/#/cn/detail/@ohos%2Ftextlayoutbuilder

参考demo:

import {TextInfo,TextLayout} from '@ohos/textlayoutbuilder';  
  
@Entry  
@Component  
struct textTest{  
  @State layout:TextLayout.Layout = new TextLayout.Layout();  
  @State strTest:string = "多颜色的多颜色的多颜色的多颜色的多颜色的多颜色的多颜色的多颜色的多颜色的多颜色的多颜色的多颜色的多颜色的多颜色的多颜色的多颜色的"  
  aboutToAppear() {  
  
    let textInfo = new TextInfo();  
    textInfo.setStart(2)  
    textInfo.setEnd(8)  
    textInfo.setFontColor('#ff0000')  
    textInfo.setFontSize("10fp")  
  
    let textInfo1 = new TextInfo();  
    textInfo1.setStart(10)  
    textInfo1.setEnd(12)  
    textInfo1.setFontColor('#ff00ff')  
    textInfo1.setFontSize("20fp")  
  
    this.layout  
      .setText(this.strTest)  
      .setSpecialTextInfo(textInfo)  
      .setSpecialTextInfo(textInfo1)  
      .setSingleLine(true)  
      .setEllipsize(TextOverflow.Ellipsis)  
  }  
  build() {  
    Column(){  
      Column() {  
        TextLayout({ model: this.layout })  
      }  
    }  
  }  
}
  • 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-11 16:48:24
相关问题
HarmonyOS RichText组件无法设置字体大小
792浏览 • 1回复 待解决
JS ui支持vp、字体大小支持fp了吗?
6715浏览 • 1回复 待解决
HarmonyOS 字体大小如何设置?
2184浏览 • 1回复 待解决
HarmonyOS webview字体大小设置
765浏览 • 1回复 待解决
HarmonyOS 如何支持表情文本
1882浏览 • 2回复 待解决
HarmonyOS 怎么获取系统字体大小
1496浏览 • 1回复 待解决
应用内字体大小设置调整
1020浏览 • 1回复 待解决