往期鸿蒙5.0全套实战文章必看:(文中附带全栈鸿蒙5.0学习资料)
ContainerSpan
Text组件的子组件,用于统一管理多个Span、ImageSpan的背景色及圆角弧度。
说明
该组件从API Version 11开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
子组件
接口
ContainerSpan()
元服务API: 从API version 12开始,该接口支持在元服务中使用。
系统能力: SystemCapability.ArkUI.ArkUI.Full
属性
仅支持以下属性:
textBackgroundStyle
textBackgroundStyle(style: TextBackgroundStyle)
设置文本背景样式。子组件在不设置该属性时,将继承此属性值。
元服务API: 从API version 12开始,该接口支持在元服务中使用。
系统能力: SystemCapability.ArkUI.ArkUI.Full
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| style | TextBackgroundStyle | 是 | 文本背景样式。 默认值: { color: Color.Transparent, radius: 0 } |
attributeModifier12+
attributeModifier(modifier: AttributeModifier<ContainerSpanAttribute>)
设置组件的动态属性。
元服务API: 从API version 12开始,该接口支持在元服务中使用。
系统能力: SystemCapability.ArkUI.ArkUI.Full
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| modifier | AttributeModifier<ContainerSpanAttribute> | 是 | 动态设置组件的属性。 |
事件
不支持通用事件。
示例
该示例通过textBackgroundStyle属性展示了文本设置背景样式的效果。
// xxx.ets
@Component
@Entry
struct Index {
build() {
Column() {
Text() {
ContainerSpan() {
ImageSpan($r('app.media.app_icon'))
.width('40vp')
.height('40vp')
.verticalAlign(ImageSpanAlignment.CENTER)
Span(' Hello World ! ').fontSize('16fp').fontColor(Color.White)
}.textBackgroundStyle({color: "#7F007DFF", radius: "12vp"})
}
}.width('100%').alignItems(HorizontalAlign.Center)
}
}




被折叠的 条评论
为什么被折叠?



