99精品伊人亚洲|最近国产中文炮友|九草在线视频支援|AV网站大全最新|美女黄片免费观看|国产精品资源视频|精彩无码视频一区|91大神在线后入|伊人终合在线播放|久草综合久久中文

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

鴻蒙ArkTS聲明式組件:Text

jf_46214456 ? 來源:jf_46214456 ? 作者:jf_46214456 ? 2024-07-02 09:46 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

Text

顯示一段文本的組件。

說明:
開發(fā)前請(qǐng)熟悉鴻蒙開發(fā)指導(dǎo)文檔 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md]
該組件從API Version 7開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨(dú)標(biāo)記該內(nèi)容的起始版本。

子組件

可以包含[Span]和[ImageSpan]子組件。

接口

Text(content?: string | Resource)

從API version 9開始,該接口支持在ArkTS卡片中使用。

參數(shù):

參數(shù)名參數(shù)類型必填參數(shù)描述
contentstring[Resource]

屬性

除支持[通用屬性]和[文本通用屬性]外,還支持以下屬性:

名稱參數(shù)類型描述
textAlign[TextAlign]設(shè)置文本段落在水平方向的對(duì)齊方式。 默認(rèn)值:TextAlign.Start 說明: 文本段落寬度占滿Text組件寬度;可通過[align]屬性控制文本段落在垂直方向上的位置,此組件中不可通過align屬性控制文本段落在水平方向上的位置,即align屬性中Alignment.TopStart、Alignment.Top、Alignment.TopEnd效果相同,控制內(nèi)容在頂部,Alignment.Start、Alignment.Center、Alignment.End效果相同,控制內(nèi)容垂直居中,Alignment.BottomStart、Alignment.Bottom、Alignment.BottomEnd效果相同,控制內(nèi)容在底部。結(jié)合TextAlign屬性可控制內(nèi)容在水平方向的位置。 從API version 9開始,該接口支持在ArkTS卡片中使用。
textOverflow{overflow: [TextOverflow]}設(shè)置文本超長(zhǎng)時(shí)的顯示方式。 默認(rèn)值:{overflow: TextOverflow.Clip}**說明:**文本截?cái)嗍前醋纸財(cái)?。例如,英文以單詞為最小單位進(jìn)行截?cái)啵粜枰宰帜笧閱挝贿M(jìn)行截?cái)?,可在字母間添加零寬空格:u200B。 當(dāng)overflow設(shè)置為TextOverflow.None、TextOverflow.Clip、TextOverflow.Ellipsis時(shí),需配合maxLines使用,單獨(dú)設(shè)置不生效。設(shè)置TextOverflow.None與TextOverflow.Clip效果一樣。當(dāng)overflow設(shè)置為TextOverflow.Marquee時(shí),文本在一行內(nèi)滾動(dòng)顯示,設(shè)置maxLinescopyOption屬性均不生效。 從API version 9開始,該接口支持在ArkTS卡片中使用。
maxLinesnumber設(shè)置文本的最大行數(shù)。 默認(rèn)值:Infinity**說明:**默認(rèn)情況下,文本是自動(dòng)折行的,如果指定此參數(shù),則文本最多不會(huì)超過指定的行。如果有多余的文本,可以通過textOverflow來指定截?cái)喾绞健?從API version 9開始,該接口支持在ArkTS卡片中使用。
lineHeightstringnumber
decoration{ type: [TextDecorationType], color?: [ResourceColor] }設(shè)置文本裝飾線樣式及其顏色。 默認(rèn)值:{ type: TextDecorationType.None, color:Color.Black } 從API version 9開始,該接口支持在ArkTS卡片中使用。
baselineOffsetnumberstring
letterSpacingnumberstring
minFontSizenumberstring
maxFontSizenumberstring
textCase[TextCase]設(shè)置文本大小寫。 默認(rèn)值:TextCase.Normal 從API version 9開始,該接口支持在ArkTS卡片中使用。
copyOption9+[CopyOptions]組件支持設(shè)置文本是否可復(fù)制粘貼。 默認(rèn)值:CopyOptions.None 該接口支持在ArkTS卡片中使用。**說明:**設(shè)置copyOptions為CopyOptions.InApp或者CopyOptions.LocalDevice,長(zhǎng)按文本,會(huì)彈出文本選擇菜單,可選中文本并進(jìn)行復(fù)制、全選操作。
textShadow10+[ShadowOptions]設(shè)置文字陰影效果。
heightAdaptivePolicy10+[TextHeightAdaptivePolicy]設(shè)置文本自適應(yīng)高度的方式。 默認(rèn)值:TextHeightAdaptivePolicy.MAX_LINES_FIRST。**說明:**當(dāng)設(shè)置為TextHeightAdaptivePolicy.MAX_LINES_FIRST時(shí),優(yōu)先使用maxLines屬性來調(diào)整文本高度。如果使用maxLines屬性的布局大小超過了布局約束,則嘗試在minFontSizemaxFontSize的范圍內(nèi)縮小字體以顯示更多文本。 當(dāng)設(shè)置為TextHeightAdaptivePolicy.MIN_FONT_SIZE_FIRST時(shí),優(yōu)先使用minFontSize屬性來調(diào)整文本高度。如果使用minFontSize屬性可以將文本布局在一行中,則嘗試在minFontSizemaxFontSize的范圍內(nèi)增大字體并使用最大可能的字體大小。 當(dāng)設(shè)置為TextHeightAdaptivePolicy.LAYOUT_CONSTRAINT_FIRST時(shí),優(yōu)先使用布局約束來調(diào)整文本高度。如果布局大小超過布局約束,則嘗試在minFontSizemaxFontSize的范圍內(nèi)縮小字體以滿足布局約束。如果將字體大小縮小到minFontSize后,布局大小仍然超過布局約束,則刪除超過布局約束的行。
textIndent10+numberstring
font10+[Font]設(shè)置文本樣式。包括字體大小、字體粗細(xì)、字體族和字體風(fēng)格。

說明:
HarmonyOSOpenHarmony鴻蒙文檔籽料:mau123789是v直接拿

不支持Text內(nèi)同時(shí)存在文本內(nèi)容和Span或ImageSpan子組件。如果同時(shí)存在,只顯示Span或ImageSpan內(nèi)的內(nèi)容。

通用屬性中形狀裁剪[clip]屬性,在Text默認(rèn)值為true。

搜狗高速瀏覽器截圖20240326151547.png

事件

支持[通用事件]

示例

示例1

// xxx.ets
@Entry
@Component
struct TextExample1 {
  build() {
    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) {
      // 文本水平方向?qū)R方式設(shè)置
      // 單行文本
      Text('textAlign').fontSize(9).fontColor(0xCCCCCC)
      Text('TextAlign set to Center.')
        .textAlign(TextAlign.Center)
        .fontSize(12)
        .border({ width: 1 })
        .padding(10)
        .width('100%')
      Text('TextAlign set to Start.')
        .textAlign(TextAlign.Start)
        .fontSize(12)
        .border({ width: 1 })
        .padding(10)
        .width('100%')
      Text('TextAlign set to End.')
        .textAlign(TextAlign.End)
        .fontSize(12)
        .border({ width: 1 })
        .padding(10)
        .width('100%')

      // 多行文本
      Text('This is the text content with textAlign set to Center.')
        .textAlign(TextAlign.Center)
        .fontSize(12)
        .border({ width: 1 })
        .padding(10)
        .width('100%')
      Text('This is the text content with textAlign set to Start.')
        .textAlign(TextAlign.Start)
        .fontSize(12)
        .border({ width: 1 })
        .padding(10)
        .width('100%')
      Text('This is the text content with textAlign set to End.')
        .textAlign(TextAlign.End)
        .fontSize(12)
        .border({ width: 1 })
        .padding(10)
        .width('100%')


      // 文本超長(zhǎng)時(shí)顯示方式
      Text('TextOverflow+maxLines').fontSize(9).fontColor(0xCCCCCC)
      // 超出maxLines截?cái)鄡?nèi)容展示
      Text('This is the setting of textOverflow to Clip text content This is the setting of textOverflow to None text content. This is the setting of textOverflow to Clip text content This is the setting of textOverflow to None text content.')
        .textOverflow({ overflow: TextOverflow.Clip })
        .maxLines(1)
        .fontSize(12)
        .border({ width: 1 })
        .padding(10)

      // 超出maxLines展示省略號(hào)
      Text('This is set textOverflow to Ellipsis text content This is set textOverflow to Ellipsis text content.'.split('')
        .join('u200B'))
        .textOverflow({ overflow: TextOverflow.Ellipsis })
        .maxLines(1)
        .fontSize(12)
        .border({ width: 1 })
        .padding(10)

      Text('lineHeight').fontSize(9).fontColor(0xCCCCCC)
      Text('This is the text with the line height set. This is the text with the line height set.')
        .fontSize(12).border({ width: 1 }).padding(10)
      Text('This is the text with the line height set. This is the text with the line height set.')
        .fontSize(12).border({ width: 1 }).padding(10)
        .lineHeight(20)
    }.height(600).width(350).padding({ left: 35, right: 35, top: 35 })
  }
}

textExp1

示例2

@Entry
@Component
struct TextExample2 {
  build() {
    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) {
      Text('decoration').fontSize(9).fontColor(0xCCCCCC)
      Text('This is the text content with the decoration set to LineThrough and the color set to Red.')
        .decoration({
          type: TextDecorationType.LineThrough,
          color: Color.Red
        })
        .fontSize(12)
        .border({ width: 1 })
        .padding(10)
        .width('100%')


      Text('This is the text content with the decoration set to Overline and the color set to Red.')
        .decoration({
          type: TextDecorationType.Overline,
          color: Color.Red
        })
        .fontSize(12)
        .border({ width: 1 })
        .padding(10)
        .width('100%')


      Text('This is the text content with the decoration set to Underline and the color set to Red.')
        .decoration({
          type: TextDecorationType.Underline,
          color: Color.Red
        })
        .fontSize(12)
        .border({ width: 1 })
        .padding(10)
        .width('100%')

      // 文本基線偏移
      Text('baselineOffset').fontSize(9).fontColor(0xCCCCCC)
      Text('This is the text content with baselineOffset 0.')
        .baselineOffset(0)
        .fontSize(12)
        .border({ width: 1 })
        .padding(10)
        .width('100%')
      Text('This is the text content with baselineOffset 30.')
        .baselineOffset(30)
        .fontSize(12)
        .border({ width: 1 })
        .padding(10)
        .width('100%')
      Text('This is the text content with baselineOffset -20.')
        .baselineOffset(-20)
        .fontSize(12)
        .border({ width: 1 })
        .padding(10)
        .width('100%')

      // 文本字符間距
      Text('letterSpacing').fontSize(9).fontColor(0xCCCCCC)
      Text('This is the text content with letterSpacing 0.')
        .letterSpacing(0)
        .fontSize(12)
        .border({ width: 1 })
        .padding(10)
        .width('100%')
      Text('This is the text content with letterSpacing 3.')
        .letterSpacing(3)
        .fontSize(12)
        .border({ width: 1 })
        .padding(10)
        .width('100%')
      Text('This is the text content with letterSpacing -1.')
        .letterSpacing(-1)
        .fontSize(12)
        .border({ width: 1 })
        .padding(10)
        .width('100%')

      Text('textCase').fontSize(9).fontColor(0xCCCCCC)
      Text('This is the text content with textCase set to Normal.')
        .textCase(TextCase.Normal)
        .fontSize(12)
        .border({ width: 1 })
        .padding(10)
        .width('100%')
      // 文本全小寫展示
      Text('This is the text content with textCase set to LowerCase.')
        .textCase(TextCase.LowerCase)
        .fontSize(12)
        .border({ width: 1 })
        .padding(10)
        .width('100%')
      // 文本全大寫展示
      Text('This is the text content with textCase set to UpperCase.')
        .textCase(TextCase.UpperCase)
        .fontSize(12).border({ width: 1 }).padding(10)

    }.height(700).width(350).padding({ left: 35, right: 35, top: 35 })
  }
}

textExp1

示例3

textShadow,heightAdaptivePolicy,TextOverflow.MARQUEE使用示例:

@Entry
@Component
struct TextExample {
  build() {
    Column({ space: 8 }) {
      Text('textShadow').fontSize(9).fontColor(0xCCCCCC).margin(15).width('90%')
      // 設(shè)置文字陰影效果
      Text('textShadow')
        .width('80%')
        .height(55)
        .fontSize(40)
        .lineHeight(55)
        .textAlign(TextAlign.Center)
        .textShadow({ radius: 10, color: Color.Black, offsetX: 0, offsetY: 0 })
        .borderWidth(1)
      Divider()
      // 設(shè)置文本自適應(yīng)高度的方式
      Text('heightAdaptivePolicy').fontSize(9).fontColor(0xCCCCCC).margin(15).width('90%')
      Text('This is the text with the height adaptive policy set')
        .width('80%')
        .height(90)
        .borderWidth(1)
        .minFontSize(10)
        .maxFontSize(30)
        .maxLines(3)
        .textOverflow({ overflow: TextOverflow.Ellipsis })
        .heightAdaptivePolicy(TextHeightAdaptivePolicy.MAX_LINES_FIRST)
      Text('This is the text with the height adaptive policy set')
        .width('80%')
        .height(90)
        .borderWidth(1)
        .minFontSize(10)
        .maxFontSize(30)
        .maxLines(3)
        .textOverflow({ overflow: TextOverflow.Ellipsis })
        .heightAdaptivePolicy(TextHeightAdaptivePolicy.MIN_FONT_SIZE_FIRST)
      Text('This is the text with the height adaptive policy set')
        .width('80%')
        .height(90)
        .borderWidth(1)
        .minFontSize(10)
        .maxFontSize(30)
        .maxLines(3)
        .textOverflow({ overflow: TextOverflow.Ellipsis })
        .heightAdaptivePolicy(TextHeightAdaptivePolicy.LAYOUT_CONSTRAINT_FIRST)
      Divider()
      Text('marquee').fontSize(9).fontColor(0xCCCCCC).margin(15).width('90%')
      // 設(shè)置文本超長(zhǎng)時(shí)以跑馬燈的方式展示
      Text('This is the text with the text overflow set marquee')
        .width(300)
        .borderWidth(1)
        .textOverflow({ overflow: TextOverflow.MARQUEE })
    }
  }
}

審核編輯 黃宇

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • 組件
    +關(guān)注

    關(guān)注

    1

    文章

    532

    瀏覽量

    18424
  • 鴻蒙
    +關(guān)注

    關(guān)注

    60

    文章

    2620

    瀏覽量

    44052
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評(píng)論

    相關(guān)推薦
    熱點(diǎn)推薦

    了解鴻蒙OS Text組件

    文本(Text)是用來顯示字符串的組件,在界面上顯示為一塊文本區(qū)域。Text 作為一個(gè)基本組件,有很多擴(kuò)展,常見的有按鈕組件 Button,
    的頭像 發(fā)表于 01-29 15:24 ?1558次閱讀
    了解<b class='flag-5'>鴻蒙</b>OS <b class='flag-5'>Text</b><b class='flag-5'>組件</b>

    鴻蒙入門實(shí)戰(zhàn)-ArkTS開發(fā)

    聲明UI基本概念 應(yīng)用界面是由一個(gè)個(gè)頁面組成,ArkTS是由ArkUI框架提供,用于以聲明開發(fā)范式開發(fā)界面的語言。
    發(fā)表于 01-16 17:27

    HarmonyOS/OpenHarmony應(yīng)用開發(fā)-ArkTS聲明開發(fā)范式

    軌跡。狀態(tài)與數(shù)據(jù)管理狀態(tài)數(shù)據(jù)管理作為基于ArkTS聲明開發(fā)范式的特色,通過功能不同的裝飾器給開發(fā)者提供了清晰的頁面更新渲染流程和管道。狀態(tài)管理包括UI組件狀態(tài)和應(yīng)用程序狀態(tài),兩者協(xié)
    發(fā)表于 01-17 15:09

    HarmonyOS/OpenHarmony應(yīng)用開發(fā)-ArkTS語言聲明UI描述

    ArkTS聲明方式組合和擴(kuò)展組件來描述應(yīng)用程序的UI,同時(shí)還提供了基本的屬性、事件和子組件配置方法,幫助開發(fā)者實(shí)現(xiàn)應(yīng)用交互邏輯。 一、創(chuàng)建組件
    發(fā)表于 06-05 15:26

    HarmonyOS/OpenHarmony原生應(yīng)用-ArkTS萬能卡片組件Text

    顯示一段文本的組件。該組件從API Version 7開始支持。用上角標(biāo)單獨(dú)標(biāo)記該內(nèi)容的起始版本??梢园琒pan子組件。 一、接口 Text(content?: string | R
    發(fā)表于 10-19 15:13

    鴻蒙ArkTS聲明組件:Blank

    空白填充組件,在容器主軸方向上,空白填充組件具有自動(dòng)填充容器空余部分的能力。僅當(dāng)父組件為Row/Column/Flex時(shí)生效。
    的頭像 發(fā)表于 06-19 16:21 ?1005次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>組件</b>:Blank

    鴻蒙ArkTS聲明組件:Marquee

    跑馬燈組件,用于滾動(dòng)展示一段單行文本。僅當(dāng)文本內(nèi)容寬度超過跑馬燈組件寬度時(shí)滾動(dòng),不超過時(shí)不滾動(dòng)。
    的頭像 發(fā)表于 06-25 15:52 ?861次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>組件</b>:Marquee

    鴻蒙ArkTS聲明組件:NavDestination

    作為NavRouter組件的子組件,用于顯示導(dǎo)航內(nèi)容區(qū)。
    的頭像 發(fā)表于 06-27 14:05 ?1128次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>組件</b>:NavDestination

    鴻蒙ArkTS聲明組件:【RichText】

    富文本組件,解析并顯示HTML格式文本。
    的頭像 發(fā)表于 06-29 09:35 ?1425次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>組件</b>:【RichText】

    鴻蒙ArkTS聲明組件:ScrollBar

    滾動(dòng)條組件ScrollBar,用于配合可滾動(dòng)組件使用,如List、Grid、Scroll。
    的頭像 發(fā)表于 07-01 15:52 ?1026次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>組件</b>:ScrollBar

    鴻蒙ArkTS聲明組件:Span

    作為Text組件的子組件,用于顯示行內(nèi)文本的組件
    的頭像 發(fā)表于 07-01 09:14 ?856次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>組件</b>:Span

    鴻蒙ArkTS聲明組件:StepperItem

    用作[Stepper]組件的頁面子組件。
    的頭像 發(fā)表于 07-02 17:47 ?648次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>組件</b>:StepperItem

    鴻蒙ArkTS聲明組件:TextArea

    多行文本輸入框組件,當(dāng)輸入的文本內(nèi)容超過組件寬度時(shí)會(huì)自動(dòng)換行顯示。
    的頭像 發(fā)表于 07-02 15:02 ?1440次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>組件</b>:TextArea

    鴻蒙ArkTS聲明組件:TextInput

    單行文本輸入框組件。
    的頭像 發(fā)表于 07-03 09:14 ?2076次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>組件</b>:TextInput

    鴻蒙ArkTS聲明組件:TextPicker

    滑動(dòng)選擇文本內(nèi)容的組件
    的頭像 發(fā)表于 07-03 15:07 ?1152次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>聲明</b><b class='flag-5'>式</b><b class='flag-5'>組件</b>:TextPicker