Span
作為Text組件的子組件,用于顯示行內文本的組件。
說明:
開發前請熟悉鴻蒙開發指導文檔 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md
]
該組件從API Version 7開始支持。后續版本如有新增內容,則采用上角標單獨標記該內容的起始版本。該組件從API Version 10開始支持繼承父組件Text的屬性,即如果子組件未設置屬性且父組件設置屬性,則繼承父組件設置的屬性。支持繼承的屬性僅包括:fontColor、fontSize、fontStyle、fontWeight、decoration、letterSpacing、textCase、fontfamily。
子組件
無
接口
Span(value: string | Resource)
從API version 9開始,該接口支持在ArkTS卡片中使用。
參數:
參數名 | 參數類型 | 必填 | 參數描述 |
---|---|---|---|
value | string | [Resource] | 是 |
屬性
通用屬性方法僅支持除lineHeight以外的[通用文本樣式]。
名稱 | 參數類型 | 描述 |
---|---|---|
decoration | { type: [TextDecorationType], color?: [ResourceColor]} | 設置文本裝飾線樣式及其顏色。 默認值:{ type: TextDecorationType.None color:Color.Black } 從API version 9開始,該接口支持在ArkTS卡片中使用。 |
letterSpacing | number | string |
textCase | [TextCase] | 設置文本大小寫。 默認值:TextCase.Normal 從API version 9開始,該接口支持在ArkTS卡片中使用。 |
font10+ | [Font] | 設置文本樣式。包括字體大小、字體粗細、字體族和字體風格。 |
事件
通用事件僅支持[點擊事件]。
說明:
HarmonyOS與OpenHarmony鴻蒙文檔籽料:mau123789是v直接拿
由于Span組件無尺寸信息,因此點擊事件返回的ClickEvent對象的target屬性無效。
示例
// xxx.ets
@Entry
@Component
struct SpanExample {
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) {
Text('Basic Usage').fontSize(9).fontColor(0xCCCCCC)
Text() {
Span('In Line')
Span(' Component')
Span(' !')
}
Text() {
Span('This is the Span component').fontSize(12).textCase(TextCase.Normal)
.decoration({ type: TextDecorationType.None, color: Color.Red })
}
// 文本橫線添加
Text('Text Decoration').fontSize(9).fontColor(0xCCCCCC)
Text() {
Span('I am Underline-span').decoration({ type: TextDecorationType.Underline, color: Color.Red }).fontSize(12)
}
Text() {
Span('I am LineThrough-span')
.decoration({ type: TextDecorationType.LineThrough, color: Color.Red })
.fontSize(12)
}
Text() {
Span('I am Overline-span').decoration({ type: TextDecorationType.Overline, color: Color.Red }).fontSize(12)
}
// 文本字符間距
Text('LetterSpacing').fontSize(9).fontColor(0xCCCCCC)
Text() {
Span('span letter spacing')
.letterSpacing(0)
.fontSize(12)
}
Text() {
Span('span letter spacing')
.letterSpacing(-2)
.fontSize(12)
}
Text() {
Span('span letter spacing')
.letterSpacing(3)
.fontSize(12)
}
// 文本大小寫展示設置
Text('Text Case').fontSize(9).fontColor(0xCCCCCC)
Text() {
Span('I am Lower-span').fontSize(12)
.textCase(TextCase.LowerCase)
.decoration({ type: TextDecorationType.None })
}
Text() {
Span('I am Upper-span').fontSize(12)
.textCase(TextCase.UpperCase)
.decoration({ type: TextDecorationType.None })
}
}.width('100%').height(250).padding({ left: 35, right: 35, top: 35 })
}
}
審核編輯 黃宇
-
鴻蒙
+關注
關注
57文章
2392瀏覽量
43055
發布評論請先 登錄
相關推薦
評論