HarmonyOS 如何实现组件的宽度会跟随字体的长度变长

下划线会跟随字体的长度来变化的,如何实现?

HarmonyOS
2024-12-25 11:48:03
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
put_get

使用Text组件,设置border属性,参考示例如下:

@Entry
@Component
struct TextPage {
  @State message: string = 'Hello World';

  build() {
    Column() {
      Text('TextPage')
        .fontSize(20)
        .fontWeight(500)
        .lineHeight(22)
        .margin({ top: 17, bottom: 7 })
        .border({
          width: {
            left: 0,
            right: 0,
            top: 0,
            bottom: 2
          },
          color: { bottom: Color.Blue },
          radius: 0,
          style: {
            bottom: BorderStyle.Solid,
          }
        })
      Text('TextPage2')
        .fontSize(20)
        .fontWeight(500)
        .lineHeight(22)
        .margin({ top: 17, bottom: 7 })
        .border({
          width: {
            left: 0,
            right: 0,
            top: 0,
            bottom: 2
          },
          color: { bottom: Color.Blue },
          radius: 0,
          style: {
            bottom: BorderStyle.Solid,
          }
        })
    }
    .height('100%')
    .width('100%')
  }
}
分享
微博
QQ
微信
回复
2024-12-25 15:17:30
相关问题
HarmonyOS 如何获取组件宽度
537浏览 • 1回复 待解决
HarmonyOS 跟随键盘工具栏如何实现
67浏览 • 1回复 待解决
text组件字体如何加粗?
538浏览 • 1回复 待解决
如何获取当前组件宽度
499浏览 • 1回复 待解决
HarmonyOS如何测量Text组件宽度
609浏览 • 1回复 待解决
HarmonyOS NavPathStack长度如何监控
598浏览 • 1回复 待解决
Tab组件Tabbar中字体颜色如何修改
1687浏览 • 1回复 待解决
HarmonyOS Tabs组件tabBar宽度问题
886浏览 • 1回复 待解决
获取文本Text组件宽度
752浏览 • 1回复 待解决