基础控件(Text基础配置)
1、创建文本(Text)
Text是文本组件,通常用于展示用户视图,如显示文章的文字。
Text可通过以下两种方式来创建:
1、直接创建:
Text('我是一段文本')
2、引用Resource资源,资源路径为【/resources/base/element/string.json】
Text($r('app.string.module_desc'))
添加子组件
Span只能作为Text和RichEditor组件的子组件显示文本内容。可以在一个Text内添加多个Span来显示一段信息,会取消Text显示文字。
Span组件需要写到Text组件内,单独写Span组件不会显示信息,Text与Span同时配置文本内容时,Span内容覆盖Text内容。 @Entry @Component struct ShowText { build() { Column() { Text("坚果派-红目香薰") { Span("鸿蒙-坚果派") }.fontSize(30) .margin({ top: 100 }) .border({width:2,style:BorderStyle.Solid,color:Color.Black}) .width('80%') } } }
文本样式
设置文本装饰线及颜色,通过decoration设置文本装饰线及颜色。 @Entry @Component struct ShowText { build() { Column() { Text("坚果派-红目香薰") { Span("陌上") .decoration({ type: TextDecorationType.LineThrough, color: Color.Red }) Span("人如") .decoration({ type: TextDecorationType.Underline, color: Color.Black }) Span("玉") .decoration({ type: TextDecorationType.Overline, color: Color.Gray }) }.fontSize(30) .margin({ top: 100 }) .border({width:2,style:BorderStyle.Solid,color:Color.Black}) .width('80%') .height('50%') } } }