1# Text 2 3The **Text** component is used to display a piece of textual information. 4 5> **NOTE** 6> 7> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. 8 9 10## Child Components 11 12This component can contain the [Span](ts-basic-components-span.md), [ImageSpan](ts-basic-components-imagespan.md), [SymbolSpan](ts-basic-components-symbolSpan.md), and [ContainerSpan](ts-basic-components-containerspan.md) child components. 13 14## APIs 15 16Text(content?: string | Resource , value?: TextOptions) 17 18**Widget capability**: This API can be used in ArkTS widgets since API version 9. 19 20**Atomic service API**: This API can be used in atomic services since API version 11. 21 22**System capability**: SystemCapability.ArkUI.ArkUI.Full 23 24**Parameters** 25 26| Name| Type| Mandatory| Description| 27| -------- | -------- | -------- | -------- | 28| content | string \| [Resource](ts-types.md#resource) | No| Text content. This parameter does not take effect if the component contains a **Span** child component and does not have any [styled string](ts-universal-styled-string.md#styled-string) configured. In this case, the span content is displayed, and the style of the component does not take effect.<br>Default value: **' '**| 29| value<sup>11+</sup> | [TextOptions](#textoptions11) | No| Initialization options of the component.| 30 31## Attributes 32 33In addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported. 34 35### textAlign 36 37textAlign(value: TextAlign) 38 39Sets the horizontal alignment mode of the text. 40 41The text takes up the full width of the **Text** component. 42 43To set vertical alignment for the text, use the [align](ts-universal-attributes-location.md) attribute. The **align** attribute alone does not control the horizontal position of the text. In other words, **Alignment.TopStart**, **Alignment.Top**, and **Alignment.TopEnd** produce the same effect, top-aligning the text; **Alignment.Start**, **Alignment.Center**, and **Alignment.End** produce the same effect, centered-aligning the text vertically; **Alignment.BottomStart**, **Alignment.Bottom**, and **Alignment.BottomEnd** produce the same effect, bottom-aligning the text. Yet, it can work with the **textAlign** attribute to jointly determine the horizontal position of the text. 44 45When **textAlign** is set to **TextAlign.JUSTIFY**, you must set the [wordBreak](#wordbreak11) attribute, and the text in the last line is horizontally aligned with the start edge. 46 47**Widget capability**: This API can be used in ArkTS widgets since API version 9. 48 49**Atomic service API**: This API can be used in atomic services since API version 11. 50 51**System capability**: SystemCapability.ArkUI.ArkUI.Full 52 53**Parameters** 54 55| Name| Type | Mandatory| Description | 56| ------ | ------------------------------------------- | ---- | ---------------------------------------------------------- | 57| value | [TextAlign](ts-appendix-enums.md#textalign) | Yes | Horizontal alignment of the text.<br>Default value: **TextAlign.Start**| 58 59### textOverflow 60 61textOverflow(value: { overflow: TextOverflow }) 62 63Sets the display mode when the text is too long. 64 65Text is clipped at the transition between words. To clip text in the middle of a word, add **\u200B** between characters. Since API version 11, preferably set the **wordBreak** attribute to **WordBreak.BREAK_ALL** to achieve the same purpose. For details, see [Example 4](#example-4-setting-text-wrapping-and-line-breaking). 66 67If **overflow** is set to **TextOverflow.None**, **TextOverflow.Clip**, or **TextOverflow.Ellipsis**, this attribute must be used with **maxLines** for the settings to take effect. **TextOverflow.None** produces the same effect as **TextOverflow.Clip**. 68 69If **overflow** is set to **TextOverflow.MARQUEE**, the text scrolls in a line, and neither **maxLines** nor **copyOption** takes effect. The **textAlign** attribute takes effect only when the text is not scrollable. With **overflow** set to **TextOverflow.MARQUEE**, the **clip** attribute is set to **true** by default. **TextOverflow.MARQUEE** is not available for [CustomSpan](ts-universal-styled-string.md#customspan) of the styled string. 70 71Since API version 12, **TextOverflow.MARQUEE** is available for the **ImageSpan** component, where the text and images are displayed in scrolling mode in a line. 72 73**Widget capability**: This API can be used in ArkTS widgets since API version 9. 74 75**Atomic service API**: This API can be used in atomic services since API version 11. 76 77**System capability**: SystemCapability.ArkUI.ArkUI.Full 78 79**Parameters** 80 81| Name| Type | Mandatory| Description | 82| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 83| value | {overflow: [TextOverflow](ts-appendix-enums.md#textoverflow)} | Yes | Display mode when the text is too long.<br>Default value: **{overflow: TextOverflow.Clip}**| 84 85### maxLines 86 87maxLines(value: number) 88 89Sets the maximum number of lines in the text. By default, text is automatically folded. If this attribute is specified, the text will not exceed the specified number of lines. If there is extra text, you can use [textOverflow](#textoverflow) to specify how it is displayed. 90 91**Widget capability**: This API can be used in ArkTS widgets since API version 9. 92 93**Atomic service API**: This API can be used in atomic services since API version 11. 94 95**System capability**: SystemCapability.ArkUI.ArkUI.Full 96 97**Parameters** 98 99| Name| Type | Mandatory| Description | 100| ------ | ------ | ---- | ---------------- | 101| value | number | Yes | Maximum number of lines in the text.| 102 103### lineHeight 104 105lineHeight(value: number | string | Resource) 106 107Sets the text line height. If the value is less than or equal to **0**, the line height is not limited and the font size is adaptive. If the value is of the number type, the unit fp is used. 108 109**Widget capability**: This API can be used in ArkTS widgets since API version 9. 110 111**Atomic service API**: This API can be used in atomic services since API version 11. 112 113**System capability**: SystemCapability.ArkUI.ArkUI.Full 114 115**Parameters** 116 117| Name| Type | Mandatory| Description | 118| ------ | ------------------------------------------------------------ | ---- | ---------------- | 119| value | number \| string \| [Resource](ts-types.md#resource) | Yes | Text line height.| 120 121### decoration 122 123decoration(value: DecorationStyleInterface) 124 125Sets the color, type, and style of the text decorative line. 126 127**Widget capability**: This API can be used in ArkTS widgets since API version 9. 128 129**Atomic service API**: This API can be used in atomic services since API version 11. 130 131**System capability**: SystemCapability.ArkUI.ArkUI.Full 132 133**Parameters** 134 135| Name| Type | Mandatory| Description | 136| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 137| value | [DecorationStyleInterface<sup>12+</sup>](ts-universal-styled-string.md#decorationstyleinterface) | Yes | Style of the text decorative line.<br>Default value:<br>{<br> type: TextDecorationType.None,<br> color: Color.Black,<br> style: TextDecorationStyle.SOLID <br>}<br>**NOTE**<br>The **style** parameter cannot be used in widgets.| 138 139### baselineOffset 140 141baselineOffset(value: number | string) 142 143Sets the offset of the text baseline. If the value specified is a percentage, the default value is used. 144 145Positive values shift the content upwards, while negative values shift it downwards. 146 147**Widget capability**: This API can be used in ArkTS widgets since API version 9. 148 149**Atomic service API**: This API can be used in atomic services since API version 11. 150 151**System capability**: SystemCapability.ArkUI.ArkUI.Full 152 153**Parameters** 154 155| Name| Type | Mandatory| Description | 156| ------ | -------------------------- | ---- | -------------------------------- | 157| value | number \| string | Yes | Offset of the text baseline.<br>Default value: **0**| 158 159### letterSpacing 160 161letterSpacing(value: number | string) 162 163Sets the letter spacing for a text style. If the value specified is a percentage or 0, the default value is used. 164 165If the value specified is a negative value, the text is compressed. A negative value too small may result in the text being compressed to 0 and no content being displayed. 166 167**Widget capability**: This API can be used in ArkTS widgets since API version 9. 168 169**Atomic service API**: This API can be used in atomic services since API version 11. 170 171**System capability**: SystemCapability.ArkUI.ArkUI.Full 172 173**Parameters** 174 175| Name| Type | Mandatory| Description | 176| ------ | -------------------------- | ---- | -------------- | 177| value | number \| string | Yes | Letter spacing.| 178 179### minFontSize 180 181minFontSize(value: number | string | Resource) 182 183Sets the minimum font size. 184 185For the setting to take effect, this attribute must be used together with [maxFontSize](#maxfontsize) and [maxLines](#maxlines), or layout constraint settings. In addition, it does not take effect for child components or styled strings. 186 187When the adaptive font size is used, the **fontSize** settings do not take effect. 188 189If the value of **minFontSize** is less than or equal to 0, the adaptive font size does not take effect. 190 191**Widget capability**: This API can be used in ArkTS widgets since API version 9. 192 193**Atomic service API**: This API can be used in atomic services since API version 11. 194 195**System capability**: SystemCapability.ArkUI.ArkUI.Full 196 197**Parameters** 198 199| Name| Type | Mandatory| Description | 200| ------ | ------------------------------------------------------------ | ---- | ------------------ | 201| value | number \| string \| [Resource](ts-types.md#resource) | Yes | Minimum font size.| 202 203### maxFontSize 204 205maxFontSize(value: number | string | Resource) 206 207Sets the maximum font size. 208 209For the setting to take effect, this attribute must be used together with [minFontSize](#minfontsize) and [maxLines](#maxlines), or layout constraint settings. In addition, it does not take effect for child components or styled strings. 210 211When the adaptive font size is used, the **fontSize** settings do not take effect. 212 213**Widget capability**: This API can be used in ArkTS widgets since API version 9. 214 215**Atomic service API**: This API can be used in atomic services since API version 11. 216 217**System capability**: SystemCapability.ArkUI.ArkUI.Full 218 219**Parameters** 220 221| Name| Type | Mandatory| Description | 222| ------ | ------------------------------------------------------------ | ---- | ------------------ | 223| value | number \| string \| [Resource](ts-types.md#resource) | Yes | Maximum font size.| 224 225### textCase 226 227textCase(value: TextCase) 228 229Sets the text case. 230 231**Widget capability**: This API can be used in ArkTS widgets since API version 9. 232 233**Atomic service API**: This API can be used in atomic services since API version 11. 234 235**System capability**: SystemCapability.ArkUI.ArkUI.Full 236 237**Parameters** 238 239| Name| Type | Mandatory| Description | 240| ------ | ----------------------------------------- | ---- | ----------------------------------------- | 241| value | [TextCase](ts-appendix-enums.md#textcase) | Yes | Text case.<br>Default value: **TextCase.Normal**| 242 243### fontColor 244 245fontColor(value: ResourceColor) 246 247Sets the font color. 248 249**Widget capability**: This API can be used in ArkTS widgets since API version 9. 250 251**Atomic service API**: This API can be used in atomic services since API version 11. 252 253**System capability**: SystemCapability.ArkUI.ArkUI.Full 254 255**Parameters** 256 257| Name| Type | Mandatory| Description | 258| ------ | ------------------------------------------ | ---- | ---------- | 259| value | [ResourceColor](ts-types.md#resourcecolor) | Yes | Font color.| 260 261### fontSize 262 263fontSize(value: number | string | Resource) 264 265Sets the text size. 266 267**Widget capability**: This API can be used in ArkTS widgets since API version 9. 268 269**Atomic service API**: This API can be used in atomic services since API version 11. 270 271**System capability**: SystemCapability.ArkUI.ArkUI.Full 272 273**Parameters** 274 275| Name| Type | Mandatory| Description | 276| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 277| value | number \| string \| [Resource](ts-types.md#resource) | Yes | Font size. If **fontSize** is of the number type, the unit fp is used. The default font size is 16 fp. This parameter cannot be set in percentage.| 278 279### fontStyle 280 281fontStyle(value: FontStyle) 282 283Sets the font style. 284 285**Widget capability**: This API can be used in ArkTS widgets since API version 9. 286 287**Atomic service API**: This API can be used in atomic services since API version 11. 288 289**System capability**: SystemCapability.ArkUI.ArkUI.Full 290 291**Parameters** 292 293| Name| Type | Mandatory| Description | 294| ------ | ------------------------------------------- | ---- | --------------------------------------- | 295| value | [FontStyle](ts-appendix-enums.md#fontstyle) | Yes | Font style.<br>Default value: **FontStyle.Normal**| 296 297### fontWeight 298 299fontWeight(value: number | FontWeight | string) 300 301Sets the font weight. If the value is too large, the text may be clipped depending on the font. 302 303**Widget capability**: This API can be used in ArkTS widgets since API version 9. 304 305**Atomic service API**: This API can be used in atomic services since API version 11. 306 307**System capability**: SystemCapability.ArkUI.ArkUI.Full 308 309**Parameters** 310 311| Name| Type | Mandatory| Description | 312| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 313| value | number \| [FontWeight](ts-appendix-enums.md#fontweight) \| string | Yes | Font weight. For the number type, the value range is [100, 900], at an interval of 100. The default value is **400**. A larger value indicates a heavier font weight. For the string type, only strings that represent a number, for example, **"400"**, and the following enumerated values of **FontWeight** are supported: **"bold"**, **"bolder"**, **"lighter"**, **"regular"**, and **"medium"**.<br>Default value: **FontWeight.Normal**| 314 315### fontFamily 316 317fontFamily(value: string | Resource) 318 319Sets the font family. 320 321**Widget capability**: This API can be used in ArkTS widgets since API version 9. 322 323**Atomic service API**: This API can be used in atomic services since API version 11. 324 325**System capability**: SystemCapability.ArkUI.ArkUI.Full 326 327**Parameters** 328 329| Name| Type | Mandatory| Description | 330| ------ | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | 331| value | string \| [Resource](ts-types.md#resource) | Yes | Font family. Default font: **'HarmonyOS Sans'**<br>The 'HarmonyOS Sans' font and [registered custom fonts](../js-apis-font.md) are supported for applications.<br>Only the 'HarmonyOS Sans' font is supported for widgets.| 332 333### copyOption<sup>9+</sup> 334 335copyOption(value: CopyOptions) 336 337Sets whether copy and paste is allowed. If this attribute is set to **CopyOptions.InApp** or **CopyOptions.LocalDevice**, a long press on the text will display a context menu that offers the copy and select-all options. 338 339Because widgets do not have the long press event, the context menu will not be displayed when users long press text. 340 341**Widget capability**: This API can be used in ArkTS widgets since API version 9. 342 343**Atomic service API**: This API can be used in atomic services since API version 11. 344 345**System capability**: SystemCapability.ArkUI.ArkUI.Full 346 347**Parameters** 348 349| Name| Type | Mandatory| Description | 350| ------ | ------------------------------------------------ | ---- | ---------------------------------------------------------- | 351| value | [CopyOptions](ts-appendix-enums.md#copyoptions9) | Yes | Whether copy and paste is allowed.<br>Default value: **CopyOptions.None**| 352 353### draggable<sup>9+</sup> 354 355draggable(value: boolean) 356 357Sets the drag effect of the selected text. 358 359This attribute cannot be used together with the [onDragStart](ts-universal-events-drag-drop.md) event. 360 361It must be used together with [CopyOptions](ts-appendix-enums.md#copyoptions9). When it is set to **true** and **copyOptions** is set to **CopyOptions.InApp** or **CopyOptions.LocalDevice**, the selected text can be dragged and copied to the text box. 362 363**Atomic service API**: This API can be used in atomic services since API version 11. 364 365**System capability**: SystemCapability.ArkUI.ArkUI.Full 366 367**Parameters** 368 369| Name| Type | Mandatory| Description | 370| ------ | ------- | ---- | ------------------------------------ | 371| value | boolean | Yes | Drag effect of the selected text.<br>Default value: **false**| 372 373### font<sup>10+</sup> 374 375font(value: Font) 376 377Sets the text style, covering the font size, font width, font family, and font style. 378 379**Atomic service API**: This API can be used in atomic services since API version 11. 380 381**System capability**: SystemCapability.ArkUI.ArkUI.Full 382 383**Parameters** 384 385| Name| Type | Mandatory| Description | 386| ------ | ------- | ---- | ---------- | 387| value | [Font](ts-types.md#font) | Yes | Text style.| 388 389### textShadow<sup>10+</sup> 390 391textShadow(value: ShadowOptions | Array<ShadowOptions>) 392 393Sets the text shadow. 394 395This API does not work with the **fill** attribute or coloring strategy. 396 397Since API version 11, this API supports input parameters in an array to implement multiple text shadows. 398 399**Widget capability**: This API can be used in ArkTS widgets since API version 10. 400 401**Atomic service API**: This API can be used in atomic services since API version 11. 402 403**System capability**: SystemCapability.ArkUI.ArkUI.Full 404 405**Parameters** 406 407| Name| Type | Mandatory| Description | 408| ------ | ------------------------------------------------------------ | ---- | -------------- | 409| value | [ShadowOptions](ts-universal-attributes-image-effect.md#shadowoptions) \| Array<[ShadowOptions](ts-universal-attributes-image-effect.md#shadowoptions)><sup>11+</sup> | Yes | Text shadow.| 410 411### heightAdaptivePolicy<sup>10+</sup> 412 413heightAdaptivePolicy(value: TextHeightAdaptivePolicy) 414 415Sets how the adaptive height is determined for the text. 416 417When this attribute is set to **TextHeightAdaptivePolicy.MAX_LINES_FIRST**, the [maxLines](#maxlines) attribute takes precedence for adjusting the text height. If the **maxLines** setting results in a layout beyond the layout constraints, the text will shrink to a font size between [minFontSize](#minfontsize) and [maxFontSize](#maxfontsize) to allow for more content to be shown. 418 419If this attribute is set to **TextHeightAdaptivePolicy.MIN_FONT_SIZE_FIRST**, the **minFontSize** attribute takes precedence for adjusting the text height. If the text can fit in one line with the **minFontSize** setting, the text will enlarge to the largest possible font size between **minFontSize** and **maxFontSize**. 420 421If this attribute is set to **TextHeightAdaptivePolicy.LAYOUT_CONSTRAINT_FIRST**, the layout constraints take precedence for adjusting the text height. If the resultant layout is beyond the layout constraints, the text will shrink to a font size between **minFontSize** and **maxFontSize** to respect the layout constraints. If the text still extends beyond the layout constraints after shrinking to **minFontSize**, the lines that exceed the constraints are deleted. 422 423**Atomic service API**: This API can be used in atomic services since API version 11. 424 425**System capability**: SystemCapability.ArkUI.ArkUI.Full 426 427**Parameters** 428 429| Name| Type | Mandatory| Description | 430| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 431| value | [TextHeightAdaptivePolicy](ts-appendix-enums.md#textheightadaptivepolicy10) | Yes | How the adaptive height is determined for the text.<br>Default value: **TextHeightAdaptivePolicy.MAX_LINES_FIRST**| 432 433### textIndent<sup>10+</sup> 434 435textIndent(value: Length) 436 437Sets the indent of the first line text. 438 439**Atomic service API**: This API can be used in atomic services since API version 11. 440 441**System capability**: SystemCapability.ArkUI.ArkUI.Full 442 443**Parameters** 444 445| Name| Type | Mandatory| Description | 446| ------ | ---------------------------- | ---- | ---------------------------- | 447| value | [Length](ts-types.md#length) | Yes | Indent of the first line text.<br>Default value: **0**| 448 449### wordBreak<sup>11+</sup> 450 451wordBreak(value: WordBreak) 452 453Sets the word break rule. When used with **{overflow: TextOverflow.Ellipsis}** and **maxLines**, **WordBreak.BREAK_ALL** can insert line breaks between letters when overflow occurs and display excess content with an ellipsis (...). 454 455**Atomic service API**: This API can be used in atomic services since API version 11. 456 457**System capability**: SystemCapability.ArkUI.ArkUI.Full 458 459**Parameters** 460 461| Name| Type | Mandatory| Description | 462| ------ | --------------------------------------------- | ---- | --------------------------------------------- | 463| value | [WordBreak](ts-appendix-enums.md#wordbreak11) | Yes | Word break rule.<br>Default value: **WordBreak.BREAK_WORD**| 464 465### selection<sup>11+</sup> 466 467selection(selectionStart: number, selectionEnd: number) 468 469Sets text selection. The selected text is highlighted, and a selection handle is displayed together with a menu of available actions. 470 471When **copyOption** is set to **CopyOptions.None**, the **selection** attribute is not effective. 472 473When **overflow** is set to **TextOverflow.MARQUEE**, the **selection** attribute is not effective. 474 475If the value of **selectionStart** is greater than or equal to that of **selectionEnd**, no text will be selected. The value range is [0, textSize], where **textSize** indicates the maximum number of characters in the text content. If the value is less than 0, the value **0** will be used. If the value is greater than **textSize**, **textSize** will be used. 476 477If the value of **selectionStart** or **selectionEnd** falls within the invisible area, no text will be selected. If clipping is disabled, the text selection outside of the parent component takes effect. 478 479**Atomic service API**: This API can be used in atomic services since API version 11. 480 481**System capability**: SystemCapability.ArkUI.ArkUI.Full 482 483**Parameters** 484 485| Name | Type | Mandatory| Description | 486| -------------- | ------ | ---- | ------------------------------------ | 487| selectionStart | number | Yes | Start position of the selected text.<br>Default value: **-1**| 488| selectionEnd | number | Yes | End position of the selected text.<br>Default value: **-1**| 489 490### ellipsisMode<sup>11+</sup> 491 492ellipsisMode(value: EllipsisMode) 493 494Sets the ellipsis position. For the settings to work, **overflow** must be set to **TextOverflow.Ellipsis** and **maxLines** must be specified. Setting **ellipsisMode** alone does not take effect. 495 496**EllipsisMode.START** and **EllipsisMode.CENTER** take effect only when text overflows in a single line. 497 498**Atomic service API**: This API can be used in atomic services since API version 12. 499 500**System capability**: SystemCapability.ArkUI.ArkUI.Full 501 502**Parameters** 503 504| Name| Type | Mandatory| Description | 505| ------ | --------------------------------------------------- | ---- | ----------------------------------------- | 506| value | [EllipsisMode](ts-appendix-enums.md#ellipsismode11) | Yes | Ellipsis position.<br>Default value: **EllipsisMode.END**| 507 508### enableDataDetector<sup>11+</sup> 509 510enableDataDetector(enable: boolean) 511 512Enables recognition for special entities within the text. 513 514This API only works on devices that provide text recognition. 515 516When **enableDataDetector** is set to **true**, and the **dataDetectorConfig** attribute is not set, all types of entities are recognized by default, and the **color** and **decoration** of the recognized entities will be changed to the following styles: 517 518```ts 519color: '#ff007dff' 520decoration:{ 521 type: TextDecorationType.Underline, 522 color: '#ff007dff', 523 style: TextDecorationStyle.SOLID 524} 525``` 526 527Touching and right-clicking an entity with the mouse will pop up the corresponding entity operation menu based on the type of entity, while left-clicking an entity with the mouse will directly respond to the first option of the menu. 528 529This API does not work when **overflow** is set to **TextOverflow.MARQUEE**. 530 531When **copyOption** is set to **CopyOptions.None**, the menu displayed after an entity is clicked does not provide the text selection or copy functionality. When **copyOption** is not set to **CopyOptions.None**, and **textSelectable** is set to **TextSelectableMode.UNSELECTABLE**, the entity still has the copy functionality but does not have the text selection feature. 532 533**Atomic service API**: This API can be used in atomic services since API version 12. 534 535**System capability**: SystemCapability.ArkUI.ArkUI.Full 536 537**Parameters** 538 539| Name| Type | Mandatory| Description | 540| ------ | ------- | ---- | --------------------------------- | 541| enable | boolean | Yes | Whether to enable text recognition.<br>Default value: **false**| 542 543### dataDetectorConfig<sup>11+</sup> 544 545dataDetectorConfig(config: TextDataDetectorConfig) 546 547Configures text recognition settings. 548 549This API must be used together with [enableDataDetector](#enabledatadetector11). It takes effect only when **enableDataDetector** is set to **true**. 550 551When entities A and B overlap, the following rules are followed: 552 5531. If A is a subset of B (A ⊂ B), then B is retained; otherwise, A is retained. 554 5552. If A is not a subset of B (A ⊄ B) and B is not a subset of A (B ⊄ A), and if the starting point of A is earlier than that of B (A.start < B.start), then A is retained; otherwise, B is retained. 556 557**Atomic service API**: This API can be used in atomic services since API version 12. 558 559**System capability**: SystemCapability.ArkUI.ArkUI.Full 560 561**Parameters** 562 563| Name| Type | Mandatory| Description | 564| ------ | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 565| config | [TextDataDetectorConfig](ts-text-common.md#textdatadetectorconfig11) | Yes | Text recognition configuration.| 566 567### bindSelectionMenu<sup>11+</sup> 568 569bindSelectionMenu(spanType: TextSpanType, content: CustomBuilder, responseType: TextResponseType, 570 options?: SelectionMenuOptions) 571 572Sets the custom context menu on text selection. 573 574The duration required for a long-press gesture is 600 ms for **bindSelectionMenu** and 800 ms for **bindContextMenu**. When both **bindSelectionMenu** and **bindContextMenu** are set and both are configured to be triggered by a long-press gesture, **bindSelectionMenu** is triggered first. 575 576If the custom menu is too long, embed a [Scroll](./ts-container-scroll.md) component to prevent the keyboard from being blocked. 577 578**Atomic service API**: This API can be used in atomic services since API version 12. 579 580**System capability**: SystemCapability.ArkUI.ArkUI.Full 581 582**Parameters** 583 584| Name | Type | Mandatory| Description | 585| ------------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 586| spanType | [TextSpanType](#textspantype11) | Yes | Span type of the menu.<br>Default value: **TextSpanType.TEXT** | 587| content | [CustomBuilder](ts-types.md#custombuilder8) | Yes | Content of the menu. | 588| responseType | [TextResponseType](#textresponsetype11) | Yes | Response type of the menu.<br>Default value: **TextResponseType.LONG_PRESS**| 589| options | [SelectionMenuOptions](ts-basic-components-richeditor.md#selectionmenuoptions10) | No | Options of the menu. | 590 591### fontFeature<sup>12+</sup> 592 593fontFeature(value: string) 594 595Sets the font feature, for example, monospaced digits. 596 597Format: normal \| \<feature-tag-value\> 598 599Format of **\<feature-tag-value\>**: \<string\> \[ \<integer\> \| on \| off ] 600 601There can be multiple **\<feature-tag-value\>** values, which are separated by commas (,). 602 603For example, the input format for monospaced clock fonts is "ss01" on. 604 605**Widget capability**: This API can be used in ArkTS widgets since API version 12. 606 607**Atomic service API**: This API can be used in atomic services since API version 12. 608 609**System capability**: SystemCapability.ArkUI.ArkUI.Full 610 611**Parameters** 612 613| Name| Type | Mandatory| Description | 614| ------ | ------ | ---- | -------------- | 615| value | string | Yes | Font feature.| 616 617Font feature list<br> 618 619 620Font features are advanced typographic features, such as ligatures and monospace, for OpenType fonts. They are typically used in custom fonts and require the support of the font itself. 621For more information about the font features, see [Low-level font feature settings control: the font-feature-settings property](https://www.w3.org/TR/css-fonts-3/#font-feature-settings-prop) and [The Complete CSS Demo for OpenType Features](https://sparanoid.com/lab/opentype-features/). 622 623> **NOTE** 624> 625> The **Text** component cannot contain both text and the child component **Span** or **ImageSpan**. If both of them exist, only the content in **Span** or **ImageSpan** is displayed. 626> 627> The typesetting engine rounds down the value of [width](ts-universal-attributes-size.md#width) to ensure that the value is an integer. If the typesetting engine rounds up the value instead, the right side of the text may be clipped. 628> 629> When multiple **Text** components are placed in the [Row](ts-container-row.md) container with no specific layout or space allocation settings configured, the components are laid out based on the maximum size of the container. To make sure the sum of the components' main axis sizes does not exceed the main axis size of the container, you can set [layoutWeight](ts-universal-attributes-size.md#layoutweight) or use the [flex layout](ts-universal-attributes-flex-layout.md). 630 631### lineSpacing<sup>12+</sup> 632 633lineSpacing(value: LengthMetrics) 634 635Sets the line spacing of the text. If the value specified is less than or equal to 0, the default value **0** is used. 636 637**Atomic service API**: This API can be used in atomic services since API version 12. 638 639**System capability**: SystemCapability.ArkUI.ArkUI.Full 640 641**Parameters** 642 643| Name| Type | Mandatory| Description | 644| ------ | ------------------------------------------------------------ | ---- | ---------------- | 645| value | [LengthMetrics](../js-apis-arkui-graphics.md#lengthmetrics12) | Yes | Line spacing. Default value: **0**| 646 647### privacySensitive<sup>12+</sup> 648 649privacySensitive(supported: boolean) 650 651Sets whether to enable privacy mode on widgets. 652 653**Widget capability**: This API can be used in ArkTS widgets since API version 12. 654 655**Atomic service API**: This API can be used in atomic services since API version 12. 656 657**System capability**: SystemCapability.ArkUI.ArkUI.Full 658 659**Parameters** 660 661| Name | Type | Mandatory| Description | 662| --------- | ------- | ---- | ------------------------------------------------------------ | 663| supported | boolean | Yes | Whether to enable privacy mode on widgets.<br>The value **true** means to enable privacy mode, in which case text is obscured as hyphens (-).<br>Default value: **false**<br>**NOTE**<br>If this parameter is set to **null**, privacy mode is disabled.<br>Enabling privacy mode requires [widget framework support](./ts-universal-attributes-obscured.md).| 664 665### lineBreakStrategy<sup>12+</sup> 666 667lineBreakStrategy(strategy: LineBreakStrategy) 668 669Sets the line break rule. This attribute takes effect when **wordBreak** is not set to **breakAll**. Hyphens are not supported. 670 671**Atomic service API**: This API can be used in atomic services since API version 12. 672 673**System capability**: SystemCapability.ArkUI.ArkUI.Full 674 675**Parameters** 676 677| Name | Type | Mandatory| Description | 678| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------- | 679| strategy | [LineBreakStrategy](ts-appendix-enums.md#linebreakstrategy12) | Yes | Line break rule.<br>Default value: **LineBreakStrategy.GREEDY**| 680 681### textSelectable<sup>12+</sup> 682 683textSelectable(mode: TextSelectableMode) 684 685Sets whether the text is selectable and focusable. 686 687**Atomic service API**: This API can be used in atomic services since API version 12. 688 689**System capability**: SystemCapability.ArkUI.ArkUI.Full 690 691**Parameters** 692 693| Name| Type | Mandatory| Description | 694| ------ | --------------------------------------------- | ---- | --------------------------------------------- | 695| mode | [TextSelectableMode](ts-appendix-enums.md#textselectablemode12) | Yes | Whether the text is selectable and focusable.<br>Default value: **TextSelectableMode.SELECTABLE_UNFOCUSABLE**| 696 697### editMenuOptions<sup>12+</sup> 698 699editMenuOptions(editMenu: EditMenuOptions) 700 701Sets the extended options of the custom context menu on selection, including the text content, icon, and callback. 702 703**Atomic service API**: This API can be used in atomic services since API version 12. 704 705**System capability**: SystemCapability.ArkUI.ArkUI.Full 706 707**Parameters** 708 709| Name| Type | Mandatory| Description | 710| ------ | --------------------------------------------- | ---- | --------------------------------------------- | 711| editMenu | [EditMenuOptions](ts-text-common.md#editmenuoptions) | Yes | Extended options of the custom context menu on selection.| 712 713### minFontScale<sup>12+</sup> 714 715minFontScale(scale: number | Resource) 716 717Sets the minimum font scale factor for text. 718 719**Atomic service API**: This API can be used in atomic services since API version 12. 720 721**System capability**: SystemCapability.ArkUI.ArkUI.Full 722 723**Parameters** 724 725| Name| Type | Mandatory| Description | 726| ------ | --------------------------------------------- | ---- | --------------------------------------------- | 727| scale | number \| [Resource](ts-types.md#resource) | Yes | Minimum font scale factor for text.<br>Value range: [0, 1]<br>**NOTE**<br>A value less than 0 is handed as **0**. A value greater than 1 is handed as **1**. Abnormal values are ineffective by default.| 728 729### maxFontScale<sup>12+</sup> 730 731maxFontScale(scale: number | Resource) 732 733Sets the maximum font scale factor for text. 734 735**Atomic service API**: This API can be used in atomic services since API version 12. 736 737**System capability**: SystemCapability.ArkUI.ArkUI.Full 738 739**Parameters** 740 741| Name| Type | Mandatory| Description | 742| ------ | --------------------------------------------- | ---- | --------------------------------------------- | 743| scale | number \| [Resource](ts-types.md#resource) | Yes | Maximum font scale factor for text.<br>Value range: [1, +∞)<br>**NOTE**<br>A value less than 1 is handed as **1**. Abnormal values are ineffective by default.| 744 745### halfLeading<sup>12+</sup> 746 747halfLeading(halfLeading: boolean) 748 749Sets whether half leading is enabled. 750 751The **halfLeading** settings configured within the component take precedence over those in **module.json5**. 752 753**Atomic service API**: This API can be used in atomic services since API version 12. 754 755**System capability**: SystemCapability.ArkUI.ArkUI.Full 756 757**Parameters** 758 759| Name| Type | Mandatory| Description | 760| ------ | --------------------------------------------- | ---- | --------------------------------------------- | 761| halfLeading | boolean | Yes | Whether half leading is enabled.<br>Half leading is the leading split in half and applied equally to the top and bottom edges. The value **true** means that half leading is enabled, and **false** means the opposite.<br>Default value: **false**| 762 763### font<sup>12+</sup> 764 765font(fontValue: Font, options?: FontSettingOptions) 766 767Sets the font style, with support for font settings. 768 769It is only effective for the **Text** component, not for its child components. 770 771**Widget capability**: This API can be used in ArkTS widgets since API version 12. 772 773**Atomic service API**: This API can be used in atomic services since API version 12. 774 775**System capability**: SystemCapability.ArkUI.ArkUI.Full 776 777**Parameters** 778 779| Name| Type | Mandatory| Description | 780| ------ | --------------------------------------------- | ---- | --------------------------------------------- | 781| fontValue | [Font](ts-types.md#font) | Yes | Text style.| 782| options | [FontSettingOptions](ts-text-common.md#fontsettingoptions12) | No | Font settings.| 783 784### fontWeight<sup>12+</sup> 785 786fontWeight(weight: number | FontWeight | string, options?: FontSettingOptions) 787 788Sets the text font weight, with support for font settings. 789 790It is only effective for the **Text** component, not for its child components. 791 792**Widget capability**: This API can be used in ArkTS widgets since API version 12. 793 794**Atomic service API**: This API can be used in atomic services since API version 12. 795 796**System capability**: SystemCapability.ArkUI.ArkUI.Full 797 798**Parameters** 799 800| Name| Type | Mandatory| Description | 801| ------ | --------------------------------------------- | ---- | --------------------------------------------- | 802| weight | number \| [FontWeight](ts-appendix-enums.md#fontweight) \| string | Yes | Font weight.| 803| options | [FontSettingOptions](ts-text-common.md#fontsettingoptions12) | No | Font settings.| 804 805### enableHapticFeedback<sup>13+</sup> 806 807enableHapticFeedback(isEnabled: boolean) 808 809Specifies whether to enable haptic feedback. 810 811**Atomic service API**: This API can be used in atomic services since API version 13. 812 813**System capability**: SystemCapability.ArkUI.ArkUI.Full 814 815**Parameters** 816 817| Name| Type | Mandatory| Description | 818| ------ | ------- | ---- | ---------------------------------- | 819| isEnabled | boolean | Yes | Whether to enable haptic feedback.<br>Default value: **true**| 820 821> **NOTE** 822> 823> To enable haptic feedback, you must declare the ohos.permission.VIBRATE permission under **requestPermissions** in the **module.json5** file of the project. 824> ```json 825> "requestPermissions": [ 826> { 827> "name": "ohos.permission.VIBRATE", 828> } 829> ] 830> ``` 831 832### caretColor<sup>14+</sup> 833 834caretColor(value: ResourceColor) 835 836Sets the color of the text selection handle, also known as the caret, in the text box. 837 838**Atomic service API**: This API can be used in atomic services since API version 14. 839 840**System capability**: SystemCapability.ArkUI.ArkUI.Full 841 842**Parameters** 843 844| Name| Type | Mandatory| Description | 845| ------ | ------------------------------------------ | ---- | -------------------------------------- | 846| value | [ResourceColor](ts-types.md#resourcecolor) | Yes | Color of the text selection handle.<br>Default value: **'#007DFF'**| 847 848### selectedBackgroundColor<sup>14+</sup> 849 850selectedBackgroundColor(value: ResourceColor) 851 852Sets the background color of the selected text. If the opacity is not set, a 20% opacity will be used. 853 854**Atomic service API**: This API can be used in atomic services since API version 14. 855 856**System capability**: SystemCapability.ArkUI.ArkUI.Full 857 858**Parameters** 859 860| Name| Type | Mandatory| Description | 861| ------ | ------------------------------------------ | ---- | ------------------------------------------ | 862| value | [ResourceColor](ts-types.md#resourcecolor) | Yes | Background color of the selected text.<br>By default, a 20% opacity is applied.<br>Default value: **'#007DFF'**| 863 864## TextSpanType<sup>11+</sup> 865 866Provides the [span](ts-basic-components-span.md) type information. 867 868**Atomic service API**: This API can be used in atomic services since API version 12. 869 870**System capability**: SystemCapability.ArkUI.ArkUI.Full 871 872| Name| Description| 873| -------- | -------- | 874| TEXT | Text span.| 875| IMAGE | Image span.| 876| MIXED | Mixed span, which contains both text and imagery.| 877 878## TextResponseType<sup>11+</sup> 879 880**Atomic service API**: This API can be used in atomic services since API version 12. 881 882**System capability**: SystemCapability.ArkUI.ArkUI.Full 883 884| Name | Description | 885| ---------- | ------------- | 886| RIGHT_CLICK | The menu is displayed when the component is right-clicked.| 887| LONG_PRESS | The menu is displayed when the component is long-pressed. | 888| SELECT | The menu is displayed when the component is selected.| 889 890## Events 891 892In addition to the [universal events](ts-universal-events-click.md), the following events are supported. 893 894### onCopy<sup>11+</sup> 895 896onCopy(callback:(value: string) => void) 897 898Called when data is copied to the pasteboard, which is displayed when the text box is long pressed. Currently, only text can be copied. 899 900**Atomic service API**: This API can be used in atomic services since API version 11. 901 902**System capability**: SystemCapability.ArkUI.ArkUI.Full 903 904**Parameters** 905 906| Name| Type | Mandatory| Description | 907| ------ | ------ | ---- | ---------------- | 908| value | string | Yes | Text that is copied.| 909 910### onTextSelectionChange<sup>11+</sup> 911 912onTextSelectionChange(callback: (selectionStart: number, selectionEnd: number) => void) 913 914Called when the text selection position changes. 915 916**Atomic service API**: This API can be used in atomic services since API version 12. 917 918**System capability**: SystemCapability.ArkUI.ArkUI.Full 919 920**Parameters** 921 922| Name | Type | Mandatory| Description | 923| -------------- | ------ | ---- | -------------------- | 924| selectionStart | number | Yes | Start position of the selected text.| 925| selectionEnd | number | Yes | End position of the selected text.| 926 927## TextOptions<sup>11+</sup> 928 929Describes the initialization options of the **Text** component. 930 931**Atomic service API**: This API can be used in atomic services since API version 12. 932 933**System capability**: SystemCapability.ArkUI.ArkUI.Full 934 935| Name| Type| Mandatory| Description| 936| -------- | -------- | -------- | -------- | 937| controller | [TextController](#textcontroller11) | Yes| Text controller.| 938 939## TextController<sup>11+</sup> 940 941Defines the controller of the **Text** component. 942 943**Atomic service API**: This API can be used in atomic services since API version 12. 944 945**System capability**: SystemCapability.ArkUI.ArkUI.Full 946 947### Objects to Import 948 949``` 950controller: TextController = new TextController() 951``` 952 953### closeSelectionMenu 954 955closeSelectionMenu(): void 956 957Closes the custom or default context menu on selection. 958 959**Atomic service API**: This API can be used in atomic services since API version 12. 960 961**System capability**: SystemCapability.ArkUI.ArkUI.Full 962 963### setStyledString<sup>12+</sup> 964 965setStyledString(value: StyledString): void 966 967Binds to or updates the specified styled string. 968 969**Atomic service API**: This API can be used in atomic services since API version 12. 970 971**System capability**: SystemCapability.ArkUI.ArkUI.Full 972 973**Parameters** 974 975| Name | Type | Mandatory | Description | 976| ----- | ------ | ---- | ------------------- | 977| value | [StyledString](ts-universal-styled-string.md#styledstring) | Yes | Styled string.<br>**NOTE**<br>The child class [MutableStyledString](ts-universal-styled-string.md#mutablestyledstring) of **StyledString** can also serve as the argument.| 978 979### getLayoutManager<sup>12+</sup> 980 981getLayoutManager(): LayoutManager 982 983Obtains the **LayoutManager** object. 984 985**Atomic service API**: This API can be used in atomic services since API version 12. 986 987**System capability**: SystemCapability.ArkUI.ArkUI.Full 988 989**Return value** 990 991| Type | Description | 992| ---------------------------------------- | ------- | 993| [LayoutManager](ts-text-common.md#layoutmanager12) | **LayoutManager** object.| 994 995## Example 996 997### Example 1: Setting the Text Layout 998This example demonstrates the effects of text layout attributes such as **textAlign**, **lineHeight**, **baselineOffset**, and **halfLeading**. 999```ts 1000// xxx.ets 1001@Extend(Text) 1002function style(TextAlign: TextAlign) { 1003 .textAlign(TextAlign) 1004 .fontSize(12) 1005 .border({ width: 1 }) 1006 .padding(10) 1007 .width('100%') 1008 .margin(5) 1009} 1010 1011@Entry 1012@Component 1013struct TextExample1 { 1014 @State changeTextAlignIndex: number = 0 1015 @State changeDecorationIndex: number = 0 1016 @State TextAlign: TextAlign[] = [TextAlign.Start, TextAlign.Center, TextAlign.End] 1017 @State TextAlignStr: string[] = ['Start', 'Center', 'End'] 1018 @State TextDecorationType: TextDecorationType[] = 1019 [TextDecorationType.LineThrough, TextDecorationType.Overline, TextDecorationType.Underline] 1020 @State TextDecorationTypeStr: string[] = ['LineThrough', 'Overline', 'Underline'] 1021 @State TextDecorationStyle: TextDecorationStyle[] = 1022 [TextDecorationStyle.SOLID, TextDecorationStyle.DOTTED, TextDecorationStyle.WAVY] 1023 @State TextDecorationStyleStr: string[] = ['SOLID', 'DOTTED', 'WAVY'] 1024 1025 build() { 1026 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { 1027 // Set horizontal alignment for text. 1028 // Single-line text 1029 Text('textAlign').fontSize(9).fontColor(0xCCCCCC) 1030 Text(`TextAlign set to ${this.TextAlignStr[this.changeTextAlignIndex]}.`) 1031 .style(this.TextAlign[this.changeTextAlignIndex]) 1032 1033 // Multi-line text 1034 Text(`This is the text content with textAlign set to ${this.TextAlignStr[this.changeTextAlignIndex]}.`) 1035 .style(this.TextAlign[this.changeTextAlignIndex]) 1036 .margin(5) 1037 1038 Row() { 1039 Button('TextAlign Value: ' + this.TextAlignStr[this.changeTextAlignIndex]).onClick(() => { 1040 this.changeTextAlignIndex++ 1041 if (this.changeTextAlignIndex > (this.TextAlignStr.length - 1)) { 1042 this.changeTextAlignIndex = 0 1043 } 1044 }) 1045 }.justifyContent(FlexAlign.Center).width('100%') 1046 1047 // Set the text line height. 1048 Text('lineHeight').fontSize(9).fontColor(0xCCCCCC) 1049 Text('This is the text with the line height set. This is the text with the line height set.') 1050 .style(TextAlign.Start) 1051 Text('This is the text with the line height set. This is the text with the line height set.') 1052 .style(TextAlign.Start) 1053 .lineHeight(20) 1054 1055 // Set the text baseline offset. 1056 Text('baselineOffset').fontSize(9).fontColor(0xCCCCCC) 1057 Text('This is the text content with baselineOffset 0.') 1058 .baselineOffset(0) 1059 .style(TextAlign.Start) 1060 Text('This is the text content with baselineOffset 30.') 1061 .baselineOffset(30) 1062 .style(TextAlign.Start) 1063 Text('This is the text content with baselineOffset -20.') 1064 .baselineOffset(-20) 1065 .style(TextAlign.Start) 1066 1067 // Set whether half leading is enabled. 1068 Text('halfLeading').fontSize(9).fontColor(0xCCCCCC) 1069 Text("This is the text with the halfLeading set.") 1070 .lineHeight(60) 1071 .halfLeading(true) 1072 .style(TextAlign.Start) 1073 Text("This is the text without the halfLeading set.") 1074 .lineHeight(60) 1075 .halfLeading(false) 1076 .style(TextAlign.Start) 1077 }.height(600).width('100%').padding({ left: 35, right: 35, top: 35 }) 1078 } 1079} 1080``` 1081 1082 1083### Example 2: Setting the Text Style 1084 1085This example showcases various text styles by using the **decoration**, **letterSpacing**, **textCase**, and **textShadow** attributes. 1086 1087```ts 1088@Extend(Text) 1089function style() { 1090 .fontSize(12) 1091 .border({ width: 1 }) 1092 .padding(10) 1093 .width('100%') 1094 .margin(5) 1095} 1096 1097@Entry 1098@Component 1099struct TextExample2 { 1100 @State changeDecorationIndex: number = 0 1101 @State TextDecorationType: TextDecorationType[] = 1102 [TextDecorationType.LineThrough, TextDecorationType.Overline, TextDecorationType.Underline] 1103 @State TextDecorationTypeStr: string[] = ['LineThrough', 'Overline', 'Underline'] 1104 @State TextDecorationStyle: TextDecorationStyle[] = 1105 [TextDecorationStyle.SOLID, TextDecorationStyle.DOTTED, TextDecorationStyle.WAVY] 1106 @State TextDecorationStyleStr: string[] = ['SOLID', 'DOTTED', 'WAVY'] 1107 1108 build() { 1109 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { 1110 Text('decoration').fontSize(9).fontColor(0xCCCCCC) 1111 Text('This is the text content with the decoration set to LineThrough and the color set to Red.') 1112 .decoration({ 1113 type: this.TextDecorationType[this.changeDecorationIndex], 1114 color: Color.Red, 1115 style: this.TextDecorationStyle[this.changeDecorationIndex] 1116 }) 1117 .style() 1118 .margin(5) 1119 1120 Row() { 1121 Button('Decoration Type: ' + this.TextDecorationTypeStr[this.changeDecorationIndex] + ' & ' + 1122 this.TextDecorationStyleStr[this.changeDecorationIndex]).onClick(() => { 1123 this.changeDecorationIndex++ 1124 if (this.changeDecorationIndex > (this.TextDecorationTypeStr.length - 1)) { 1125 this.changeDecorationIndex = 0 1126 } 1127 }) 1128 }.justifyContent(FlexAlign.Center).width('100%') 1129 1130 // Set the letter spacing. 1131 Text('letterSpacing').fontSize(9).fontColor(0xCCCCCC) 1132 Text('This is the text content with letterSpacing 0.') 1133 .letterSpacing(0) 1134 .style() 1135 Text('This is the text content with letterSpacing 3.') 1136 .letterSpacing(3) 1137 .style() 1138 Text('This is the text content with letterSpacing -1.') 1139 .letterSpacing(-1) 1140 .style() 1141 1142 Text('textCase').fontSize(9).fontColor(0xCCCCCC) 1143 Text('This is the text content with textCase set to Normal.') 1144 .textCase(TextCase.Normal) 1145 .style() 1146 // Display the text in lowercase. 1147 Text('This is the text content with textCase set to LowerCase.') 1148 .textCase(TextCase.LowerCase) 1149 .style() 1150 // Display the text in uppercase. 1151 Text('This is the text content with textCase set to UpperCase.') 1152 .textCase(TextCase.UpperCase) 1153 .style() 1154 1155 Text('textShadow').fontSize(9).fontColor(0xCCCCCC) 1156 // Set the text shadow. 1157 Text('textShadow') 1158 .style() 1159 .textAlign(TextAlign.Center) 1160 .fontSize(40) 1161 .textShadow({ 1162 radius: 10, 1163 color: Color.Black, 1164 offsetX: 0, 1165 offsetY: 0 1166 }) 1167 1168 }.height(600).width('100%').padding({ left: 35, right: 35, top: 35 }) 1169 } 1170} 1171``` 1172 1173 1174### Example 3: Setting Text Overflow 1175 1176This example demonstrates how to use **maxLines**, **textOverflow**, and **ellipsisMode** to display excess content with an ellipsis (...) when the text is too long. 1177 1178```ts 1179@Extend(Text) 1180function style() { 1181 .textAlign(TextAlign.Center) 1182 .fontSize(12) 1183 .border({ width: 1 }) 1184 .padding(10) 1185 .width('100%') 1186 .margin(5) 1187} 1188 1189@Entry 1190@Component 1191struct TextExample3 { 1192 @State text: string = 1193 'The text component is used to display a piece of textual information.Support universal attributes and universal text attributes.' 1194 @State ellipsisModeIndex: number = 0 1195 @State ellipsisMode: EllipsisMode[] = [EllipsisMode.START, EllipsisMode.CENTER, EllipsisMode.END] 1196 @State ellipsisModeStr: string[] = ['START', 'CENTER', 'END'] 1197 1198 build() { 1199 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { 1200 // Set the display mode when the text is too long. 1201 Text('TextOverflow+maxLines').fontSize(9).fontColor(0xCCCCCC) 1202 // Clip the text when the value of maxLines is exceeded. 1203 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.') 1204 .textOverflow({ overflow: TextOverflow.Clip }) 1205 .maxLines(1) 1206 .style() 1207 1208 // Show an ellipsis (...) when the value of maxLines is exceeded. 1209 Text('This is set textOverflow to Ellipsis text content This is set textOverflow to Ellipsis text content.') 1210 .textOverflow({ overflow: TextOverflow.Ellipsis }) 1211 .maxLines(1) 1212 .style() 1213 1214 Text('marquee').fontSize(9).fontColor(0xCCCCCC) 1215 // Set the text to continuously scroll when text overflow occurs. 1216 Text('This is the text with the text overflow set marquee') 1217 .textOverflow({ overflow: TextOverflow.MARQUEE }) 1218 .style() 1219 1220 Text('ellipsisMode').fontSize(9).fontColor(0xCCCCCC) 1221 // Set the position of the ellipsis (...) for text truncation. 1222 Text(this.text) 1223 .textOverflow({ overflow: TextOverflow.Ellipsis }) 1224 .ellipsisMode(this.ellipsisMode[this.ellipsisModeIndex]) 1225 .maxLines(1) 1226 .style() 1227 1228 Row() { 1229 Button('Ellipsis Position: ' + this.ellipsisModeStr[this.ellipsisModeIndex]).onClick(() => { 1230 this.ellipsisModeIndex++ 1231 if (this.ellipsisModeIndex > (this.ellipsisModeStr.length - 1)) { 1232 this.ellipsisModeIndex = 0 1233 } 1234 }) 1235 } 1236 }.height(600).width('100%').padding({ left: 35, right: 35, top: 35 }) 1237 } 1238} 1239``` 1240 1241 1242 1243### Example 4: Setting Text Wrapping and Line Breaking 1244 1245This example demonstrates the effects of different text wrapping and line breaking rules, as well as whether text is clipped when it exceeds the container's length, using the **wordBreak**, **lineBreakStrategy**, and **clip** attributes. 1246 1247```ts 1248// xxx.ets 1249@Extend(Text) 1250function style() { 1251 .fontSize(12) 1252 .border({ width: 1 }) 1253 .padding(10) 1254 .width('100%') 1255 .margin(5) 1256} 1257 1258@Entry 1259@Component 1260struct TextExample4 { 1261 @State text: string = 1262 'The text component is used to display a piece of textual information.Support universal attributes and universal text attributes.' 1263 @State text2: string = 1264 "They can be classified as built-in components–those directly provided by the ArkUI framework and custom components – those defined by developers" + 1265 "The built-in components include buttons radio buttons progress indicators and text You can set the rendering effect of these components in method chaining mode," + 1266 "page components are divided into independent UI units to implement independent creation development and reuse of different units on pages making pages more engineering-oriented." 1267 @State textClip: boolean = false 1268 @State wordBreakIndex: number = 0 1269 @State wordBreak: WordBreak[] = [WordBreak.NORMAL, WordBreak.BREAK_ALL, WordBreak.BREAK_WORD] 1270 @State wordBreakStr: string[] = ['NORMAL', 'BREAK_ALL', 'BREAK_WORD'] 1271 @State lineBreakStrategyIndex: number = 0 1272 @State lineBreakStrategy: LineBreakStrategy[] = 1273 [LineBreakStrategy.GREEDY, LineBreakStrategy.HIGH_QUALITY, LineBreakStrategy.BALANCED] 1274 @State lineBreakStrategyStr: string[] = ['GREEDY', 'HIGH_QUALITY', 'BALANCED'] 1275 1276 build() { 1277 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { 1278 Text('wordBreak').fontSize(9).fontColor(0xCCCCCC) 1279 // Set the word break rule. 1280 Text(this.text) 1281 .maxLines(2) 1282 .textOverflow({ overflow: TextOverflow.Ellipsis }) 1283 .wordBreak(this.wordBreak[this.wordBreakIndex]) 1284 .style() 1285 1286 Row() { 1287 Button('wordBreak Value: ' + this.wordBreakStr[this.wordBreakIndex]).onClick(() => { 1288 this.wordBreakIndex++ 1289 if (this.wordBreakIndex > (this.wordBreakStr.length - 1)) { 1290 this.wordBreakIndex = 0 1291 } 1292 }) 1293 } 1294 1295 Text('clip').fontSize(9).fontColor(0xCCCCCC) 1296 // Set whether text is clipped when it exceeds the length. 1297 Text('This is set wordBreak to WordBreak text Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu.') 1298 .wordBreak(WordBreak.NORMAL) 1299 .maxLines(2) 1300 .clip(this.textClip) 1301 .style() 1302 Row() { 1303 Button('Clip Mode: ' + this.textClip).onClick(() => { 1304 this.textClip = !this.textClip 1305 }) 1306 } 1307 1308 Text('lineBreakStrategy').fontSize(9).fontColor(0xCCCCCC) 1309 // Set the text line breaking rule. 1310 Text(this.text2) 1311 .lineBreakStrategy(this.lineBreakStrategy[this.lineBreakStrategyIndex]) 1312 .style() 1313 Row() { 1314 Button('lineBreakStrategy Value: ' + this.lineBreakStrategyStr[this.lineBreakStrategyIndex]).onClick(() => { 1315 this.lineBreakStrategyIndex++ 1316 if (this.lineBreakStrategyIndex > (this.lineBreakStrategyStr.length - 1)) { 1317 this.lineBreakStrategyIndex = 0 1318 } 1319 }) 1320 } 1321 }.height(600).width('100%').padding({ left: 35, right: 35, top: 35 }) 1322 } 1323} 1324``` 1325 1326 1327 1328### Example 5: Setting Text Selection and Copy 1329 1330This example demonstrates the effects of text selection and triggering a copy callback using the **selection** and **onCopy** APIs. 1331 1332```ts 1333// xxx.ets 1334@Entry 1335@Component 1336struct TextExample5 { 1337 @State onCopy: string = '' 1338 @State text: string = 'This is set selection to Selection text content This is set selection to Selection text content.' 1339 @State start: number = 0 1340 @State end: number = 20 1341 1342 build() { 1343 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Start }) { 1344 Text(this.text) 1345 .fontSize(12) 1346 .border({ width: 1 }) 1347 .lineHeight(20) 1348 .margin(30) 1349 .copyOption(CopyOptions.InApp) 1350 .selection(this.start, this.end) 1351 .onCopy((value: string) => { 1352 this.onCopy = value 1353 }) 1354 Button('Set text selection') 1355 .margin({left:20}) 1356 .onClick(() => { 1357 // Change the start point and end point of the text selection. 1358 this.start = 10 1359 this.end = 30 1360 }) 1361 Text(this.onCopy).fontSize(12).margin(10).key('copy') 1362 }.height(600).width(335).padding({ left: 35, right: 35, top: 35 }) 1363 } 1364} 1365``` 1366 1367 1368### Example 6: Setting Text Auto-Adaptation 1369 1370This example showcases the implementation of text auto-adaptation features using the **heightAdaptivePolicy** attribute. 1371 1372```ts 1373// xxx.ets 1374@Extend(Text) 1375function style(HeightAdaptivePolicy: TextHeightAdaptivePolicy) { 1376 .width('80%') 1377 .height(90) 1378 .borderWidth(1) 1379 .minFontSize(10) 1380 .maxFontSize(30) 1381 .maxLines(2) 1382 .margin(5) 1383 .textOverflow({ overflow: TextOverflow.Ellipsis }) 1384 .heightAdaptivePolicy(HeightAdaptivePolicy) 1385} 1386 1387@Entry 1388@Component 1389struct TextExample6 { 1390 build() { 1391 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { 1392 // Set how the adaptive height is determined for the text. 1393 Text('heightAdaptivePolicy').fontSize(9).fontColor(0xCCCCCC) 1394 Text('This is the text with the height adaptive policy set.') 1395 .style(TextHeightAdaptivePolicy.MAX_LINES_FIRST) 1396 Text('This is the text with the height adaptive policy set.') 1397 .style(TextHeightAdaptivePolicy.MIN_FONT_SIZE_FIRST) 1398 Text('This is the text with the height adaptive policy set.') 1399 .style(TextHeightAdaptivePolicy.LAYOUT_CONSTRAINT_FIRST) 1400 }.height(600).width('100%').padding({ left: 35, right: 35, top: 35 }) 1401 } 1402} 1403``` 1404 1405 1406 1407### Example 7: Setting Text Recognition 1408 1409This example demonstrates how to implement text recognition features using the **enableDataDetector** and **dataDetectorConfig** APIs. 1410 1411```ts 1412// xxx.ets 1413@Entry 1414@Component 1415struct TextExample7 { 1416 @State phoneNumber: string = '(86) (755) ********' 1417 @State url: string = 'www.********.com' 1418 @State email: string = '***@example.com' 1419 @State address: string = 'XX (province) XX (city) XX (county) XXXX' 1420 @State datetime: string = 'XX-XX-XX XXXX' 1421 @State enableDataDetector: boolean = true 1422 @State types: TextDataDetectorType[] = [] 1423 1424 build() { 1425 Row() { 1426 Column() { 1427 Text( 1428 'Phone number:' + this.phoneNumber + '\n' + 1429 'URL:' + this.url + '\n' + 1430 'Email:' + this.email + '\n' + 1431 'Address:' + this.address + '\n' + 1432 'Time:' + this.datetime 1433 ) 1434 .fontSize(16) 1435 .copyOption(CopyOptions.InApp) 1436 .enableDataDetector(this.enableDataDetector) 1437 .dataDetectorConfig({types : this.types, onDetectResultUpdate: (result: string)=>{}}) 1438 .textAlign(TextAlign.Center) 1439 .borderWidth(1) 1440 .padding(10) 1441 .width('100%') 1442 } 1443 .width('100%') 1444 } 1445 .height('100%') 1446 } 1447} 1448``` 1449 1450 1451 1452### Example 8: Binding Text to a Custom Menu 1453 1454This example showcases how to bind text to a custom menu using the **bindSelectionMenu**, **onTextSelectionChange**, and **closeSelectionMenu** APIs. 1455 1456```ts 1457// xxx.ets 1458@Entry 1459@Component 1460struct TextExample8 { 1461 controller: TextController = new TextController() 1462 options: TextOptions = { controller: this.controller } 1463 1464 build() { 1465 Column() { 1466 Column() { 1467 Text(undefined, this.options) { 1468 Span('Hello World') 1469 ImageSpan($r('app.media.icon')) 1470 .width('100px') 1471 .height('100px') 1472 .objectFit(ImageFit.Fill) 1473 .verticalAlign(ImageSpanAlignment.CENTER) 1474 } 1475 .copyOption(CopyOptions.InApp) 1476 .bindSelectionMenu(TextSpanType.IMAGE, this.LongPressImageCustomMenu, TextResponseType.LONG_PRESS, { 1477 onDisappear: () => { 1478 console.info(`Callback when the custom menu is closed`); 1479 }, 1480 onAppear: () => { 1481 console.info(`Callback when the custom menu is displayed`); 1482 } 1483 }) 1484 .bindSelectionMenu(TextSpanType.TEXT, this.RightClickTextCustomMenu, TextResponseType.RIGHT_CLICK) 1485 .bindSelectionMenu(TextSpanType.MIXED, this.SelectMixCustomMenu, TextResponseType.SELECT) 1486 .onTextSelectionChange((selectionStart: number, selectionEnd: number) => { 1487 console.info(`Callback when the text selection changes, selectionStart: ${selectionStart}, selectionEnd: ${selectionEnd}`); 1488 }) 1489 .borderWidth(1) 1490 .borderColor(Color.Red) 1491 .width(200) 1492 .height(100) 1493 } 1494 .width('100%') 1495 .backgroundColor(Color.White) 1496 .alignItems(HorizontalAlign.Start) 1497 .padding(25) 1498 } 1499 .height('100%') 1500 } 1501 1502 @Builder 1503 RightClickTextCustomMenu() { 1504 Column() { 1505 Menu() { 1506 MenuItemGroup() { 1507 MenuItem({ startIcon: $r('app.media.app_icon'), content: "Right Click Menu 1", labelInfo: "" }) 1508 .onClick((event) => { 1509 this.controller.closeSelectionMenu() 1510 }) 1511 MenuItem({ startIcon: $r('app.media.app_icon'), content: "Right Click Menu 2", labelInfo: "" }) 1512 MenuItem({ startIcon: $r('app.media.app_icon'), content: "Right Click Menu 3", labelInfo: "" }) 1513 } 1514 } 1515 .MenuStyles() 1516 } 1517 } 1518 1519 @Builder 1520 LongPressImageCustomMenu() { 1521 Column() { 1522 Menu() { 1523 MenuItemGroup() { 1524 MenuItem({ startIcon: $r('app.media.app_icon'), content: "Long Press Image Menu 1", labelInfo: "" }) 1525 .onClick((event) => { 1526 this.controller.closeSelectionMenu() 1527 }) 1528 MenuItem({ startIcon: $r('app.media.app_icon'), content: "Long Press Image Menu 2", labelInfo: "" }) 1529 MenuItem({ startIcon: $r('app.media.app_icon'), content: "Long Press Image Menu 3", labelInfo: "" }) 1530 } 1531 } 1532 .MenuStyles() 1533 } 1534 } 1535 1536 @Builder 1537 SelectMixCustomMenu() { 1538 Column() { 1539 Menu() { 1540 MenuItemGroup() { 1541 MenuItem({ startIcon: $r('app.media.app_icon'), content: "Select Mixed Menu 1", labelInfo: "" }) 1542 .onClick((event) => { 1543 this.controller.closeSelectionMenu() 1544 }) 1545 MenuItem({ startIcon: $r('app.media.app_icon'), content: "Select Mixed Menu 2", labelInfo: "" }) 1546 MenuItem({ startIcon: $r('app.media.app_icon'), content: "Select Mixed Menu 3", labelInfo: "" }) 1547 } 1548 } 1549 .MenuStyles() 1550 } 1551 } 1552} 1553 1554@Extend(Menu) 1555function MenuStyles() { 1556 .radius($r('sys.float.ohos_id_corner_radius_card')) 1557 .clip(true) 1558 .backgroundColor('#F0F0F0') 1559} 1560``` 1561 1562 1563 1564### Example 9: Setting Text Features and Line Spacing 1565 1566This example demonstrates the effects of setting text features and line spacing using the **fontFeature** and **lineSpacing** APIs. 1567 1568```ts 1569// xxx.ets 1570import { LengthMetrics } from '@kit.ArkUI' 1571 1572@Extend(Text) 1573function style() { 1574 .fontSize(12) 1575 .border({ width: 1 }) 1576 .width('100%') 1577 // .margin(5) 1578} 1579 1580@Entry 1581@Component 1582struct TextExample9 { 1583 build() { 1584 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { 1585 Text('lineSpacing').fontSize(9).fontColor(0xCCCCCC) 1586 // Set the line spacing. 1587 Text('This is a context with no lineSpacing set.') 1588 .lineSpacing(undefined) 1589 .style() 1590 Text('This is a context with lineSpacing set to 20_px.') 1591 .lineSpacing(LengthMetrics.px(20)) 1592 .style() 1593 Text('This is the context with lineSpacing set to 20_vp.') 1594 .lineSpacing(LengthMetrics.vp(20)) 1595 .style() 1596 Text('This is the context with lineSpacing set to 20_fp.') 1597 .lineSpacing(LengthMetrics.fp(20)) 1598 .style() 1599 Text('This is the context with lineSpacing set to 20_lpx.') 1600 .lineSpacing(LengthMetrics.lpx(20)) 1601 .style() 1602 Text('This is the context with lineSpacing set to 100%.') 1603 .lineSpacing(LengthMetrics.percent(1)) 1604 .style() 1605 1606 Text('fontFeature').fontSize(9).fontColor(0xCCCCCC) 1607 // Set text features. 1608 Text('This is ss01 on : 0123456789') 1609 .fontFeature("\"ss01\" on") 1610 .style() 1611 Text('This is ss01 off: 0123456789') 1612 .fontFeature("\"ss01\" off") 1613 .style() 1614 }.height(300).width(350).padding({ left: 35, right: 35, top: 35 }) 1615 } 1616} 1617``` 1618 1619 1620 1621### Example 10: Obtaining Text Information 1622 1623This example shows how to obtain text information by calling the layout manager object of the text using the **getLayoutManager** API. 1624 1625```ts 1626// xxx.ets 1627import { text } from '@kit.ArkGraphics2D' 1628 1629@Entry 1630@Component 1631struct TextExample10 { 1632 @State lineCount: string = "" 1633 @State glyphPositionAtCoordinate: string = "" 1634 @State lineMetrics: string = "" 1635 @State rectsForRangeStr: string = "" 1636 controller: TextController = new TextController() 1637 @State textStr: string = 1638 'Hello World!' 1639 1640 build() { 1641 Scroll() { 1642 Column() { 1643 Text('Use getLayoutManager to get layout information') 1644 .fontSize(15) 1645 .fontColor(0xCCCCCC) 1646 .width('90%') 1647 .padding(10) 1648 Text(this.textStr, { controller: this.controller }) 1649 .fontSize(25) 1650 .borderWidth(1) 1651 .onAreaChange(() => { 1652 let layoutManager: LayoutManager = this.controller.getLayoutManager() 1653 this.lineCount = "LineCount: " + layoutManager.getLineCount() 1654 }) 1655 1656 Text('LineCount').fontSize(15).fontColor(0xCCCCCC).width('90%').padding(10) 1657 Text(this.lineCount) 1658 1659 Text('GlyphPositionAtCoordinate').fontSize(15).fontColor(0xCCCCCC).width('90%').padding(10) 1660 Button("Relative Component Coordinates [150,50]") 1661 .onClick(() => { 1662 let layoutManager: LayoutManager = this.controller.getLayoutManager() 1663 let position: PositionWithAffinity = layoutManager.getGlyphPositionAtCoordinate(150, 50) 1664 this.glyphPositionAtCoordinate = 1665 "Relative coordinates [150,50] glyphPositionAtCoordinate position: " + position.position + " affinity: " + 1666 position.affinity 1667 }) 1668 .margin({ bottom: 20, top: 10 }) 1669 Text(this.glyphPositionAtCoordinate) 1670 1671 Text('LineMetrics').fontSize(15).fontColor(0xCCCCCC).width('90%').padding(10) 1672 Button("Line Metrics") 1673 .onClick(() => { 1674 let layoutManager: LayoutManager = this.controller.getLayoutManager() 1675 let lineMetrics: LineMetrics = layoutManager.getLineMetrics(0) 1676 this.lineMetrics = "lineMetrics is " + JSON.stringify(lineMetrics) + "\n\n" 1677 let runMetrics = lineMetrics.runMetrics 1678 runMetrics.forEach((value, key) => { 1679 this.lineMetrics += "runMetrics key is " + key + " " + JSON.stringify(value) + "\n\n" 1680 }) 1681 }) 1682 .margin({ bottom: 20, top: 10 }) 1683 Text(this.lineMetrics) 1684 1685 Text('getRectsForRange').fontSize(15).fontColor(0xCCCCCC).width('90%').padding(10) 1686 Button("Drawing Area Info for Characters/Placeholders within Specified Text Range") 1687 .onClick(() => { 1688 let layoutManager: LayoutManager = this.controller.getLayoutManager() 1689 let range: TextRange = { start: 0, end: 1 } 1690 let rectsForRangeInfo: text.TextBox[] = 1691 layoutManager.getRectsForRange(range, text.RectWidthStyle.TIGHT, text.RectHeightStyle.TIGHT) 1692 this.rectsForRangeStr = "getRectsForRange result is " + "\n\n" 1693 rectsForRangeInfo.forEach((value, key) => { 1694 this.rectsForRangeStr += "rectsForRange key is " + key + " " + JSON.stringify(value) + "\n\n" 1695 }) 1696 }) 1697 .margin({ bottom: 20, top: 10 }) 1698 Text(this.rectsForRangeStr) 1699 } 1700 .margin({ top: 100, left: 8, right: 8 }) 1701 } 1702 } 1703} 1704``` 1705 1706 1707 1708### Example 11: Implementing Keyboard-based Text Selection 1709 1710This example demonstrates how to implement the feature to select text using the keyboard by setting the **textSelectable** attribute to **TextSelectMode.SELECTABLE_FOCUSABLE**. 1711 1712```ts 1713// xxx.ets 1714@Entry 1715@Component 1716struct TextExample11 { 1717 @State message: string = 'TextTextTextTextTextTextTextText' + 'TextTextTextTextTextTextTextTextTextTextTextTextTextTextTextText' 1718 1719 build() { 1720 Column() { 1721 Text(this.message) 1722 .width(300) 1723 .height(100) 1724 .maxLines(5) 1725 .fontColor(Color.Black) 1726 .copyOption(CopyOptions.InApp) 1727 .selection(3, 8) 1728 .textSelectable(TextSelectableMode.SELECTABLE_FOCUSABLE) 1729 }.width('100%').margin({ top: 100 }) 1730 } 1731} 1732``` 1733 1734 1735 1736### Example 12: Setting Custom Menu Extensions 1737 1738This example demonstrates how to use the **editMenuOptions** API to create custom menu extensions for text settings. It includes customizing text content, icons, and callbacks for these extensions. 1739 1740```ts 1741// xxx.ets 1742@Entry 1743@Component 1744struct TextExample12 { 1745 @State text: string = 'Text editMenuOptions' 1746 onCreateMenu = (menuItems: Array<TextMenuItem>) => { 1747 let item1: TextMenuItem = { 1748 content: 'custom1', 1749 icon: $r('app.media.startIcon'), 1750 id: TextMenuItemId.of('custom1'), 1751 } 1752 let item2: TextMenuItem = { 1753 content: 'custom2', 1754 id: TextMenuItemId.of('custom2'), 1755 icon: $r('app.media.startIcon'), 1756 } 1757 menuItems.push(item1) 1758 menuItems.unshift(item2) 1759 return menuItems 1760 } 1761 onMenuItemClick = (menuItem: TextMenuItem, textRange: TextRange) => { 1762 if (menuItem.id.equals(TextMenuItemId.of("custom2"))) { 1763 console.log("Intercept id: custom2 start:" + textRange.start + "; end:" + textRange.end) 1764 return true 1765 } 1766 if (menuItem.id.equals(TextMenuItemId.COPY)) { 1767 console.log("Intercept COPY start:" + textRange.start + "; end:" + textRange.end) 1768 return true 1769 } 1770 if (menuItem.id.equals(TextMenuItemId.SELECT_ALL)) { 1771 console.log("Do not intercept SELECT_ALL start:" + textRange.start + "; end:" + textRange.end) 1772 return false 1773 } 1774 return false 1775 } 1776 @State editMenuOptions: EditMenuOptions = { 1777 onCreateMenu: this.onCreateMenu, onMenuItemClick: this.onMenuItemClick 1778 } 1779 1780 build() { 1781 Column() { 1782 Text(this.text) 1783 .fontSize(20) 1784 .copyOption(CopyOptions.LocalDevice) 1785 .editMenuOptions(this.editMenuOptions) 1786 .margin({ top: 100 }) 1787 } 1788 .width("90%") 1789 .margin("5%") 1790 } 1791} 1792``` 1793 1794 1795 1796### Example 13: Securing Sensitive Information 1797 1798This example illustrates how to secure sensitive information using the **privacySensitive** attribute. Note that the display requires widget framework support. 1799 1800```ts 1801// xxx.ets 1802@Entry 1803@Component 1804struct TextExample13 { 1805 build() { 1806 Column({ space: 10 }) { 1807 Text("privacySensitive") 1808 .privacySensitive(true) 1809 .margin({top :30}) 1810 } 1811 .alignItems(HorizontalAlign.Center) 1812 .width("100%") 1813 } 1814} 1815``` 1816 1817 1818