1# Text Component Common APIs 2 3>**NOTE** 4> 5>This topic covers the common APIs of text components. 6>The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. 7 8## CaretStyle<sup>10+</sup> 9 10**Atomic service API**: This API can be used in atomic services since API version 11. 11 12**System capability**: SystemCapability.ArkUI.ArkUI.Full 13 14| Name| Type | Mandatory| Description| 15| ------ | ------------------------------------------ | ---- | -------- | 16| width | [Length](ts-types.md#length) | No | Caret size. It cannot be set in percentage.<br>Default value: **'2vp'**.| 17| color | [ResourceColor](ts-types.md#resourcecolor) | No | Caret color.<br>Default value: **'#ff007dff'**.| 18 19## LayoutManager<sup>12+</sup> 20 21Implements a **LayoutManager** object. 22 23> **NOTE** 24> 25> After the text content is changed, you must wait for the layout to be completed before you can obtain the most up-to-date layout information. 26 27### Objects to Import 28The following uses the **Text** component as an example. 29``` 30controller: TextController = new TextController() 31let layoutManager: LayoutManager = this.controller.getLayoutManager(); 32``` 33 34### getLineCount 35 36getLineCount(): number 37 38Obtains the total number of lines in the component. 39 40**Atomic service API**: This API can be used in atomic services since API version 12. 41 42**System capability**: SystemCapability.ArkUI.ArkUI.Full 43 44**Return value** 45 46| Type | Description | 47| ------ | --------- | 48| number | Total number of lines in the component.| 49 50### getGlyphPositionAtCoordinate 51 52getGlyphPositionAtCoordinate(x: number, y: number): PositionWithAffinity 53 54Obtains the position of a glyph close to a given coordinate. 55 56**Atomic service API**: This API can be used in atomic services since API version 12. 57 58**System capability**: SystemCapability.ArkUI.ArkUI.Full 59 60**Parameters** 61 62| Name | Type | Mandatory | Description | 63| ------ | ------ | ---- | -------------------- | 64| x | number | Yes | X coordinate relative to the component.<br>Unit: px| 65| y | number | Yes | Y coordinate relative to the component.<br>Unit: px| 66 67**Return value** 68 69| Type | Description | 70| --------------------------------------------- | ----------- | 71| [PositionWithAffinity](#positionwithaffinity12) | Position of the glyph.| 72 73### getLineMetrics 74 75getLineMetrics(lineNumber: number): LineMetrics 76 77Obtains the information about the specified line, including line metrics, text style information, and font properties. 78 79**Atomic service API**: This API can be used in atomic services since API version 12. 80 81**System capability**: SystemCapability.ArkUI.ArkUI.Full 82 83**Parameters** 84 85| Name | Type | Mandatory | Description | 86| ------ | ------ | ---- | -------------------- | 87| lineNumber | number | Yes | Line number, which is zero-based.| 88 89**Return value** 90 91| Type | Description | 92| ---------------------------------------- | -------- | 93| [LineMetrics](#linemetrics12) | Information about the specified line, including line metrics, text style information, and font properties.<br>Returns an invalid value if the line number is less than 0 or exceeds the actual number of lines.| 94 95### getRectsForRange<sup>14+</sup> 96 97getRectsForRange(range: TextRange, widthStyle: RectWidthStyle, heightStyle: RectHeightStyle): Array\<TextBox> 98 99Obtains the drawing area information for characters or placeholders within a specified text range, based on the specified width and height of a rectangle. 100 101**Atomic service API**: This API can be used in atomic services since API version 14. 102 103**System capability**: SystemCapability.ArkUI.ArkUI.Full 104 105**Parameters** 106 107| Name | Type | Mandatory| Description | 108| ----------- | ----------------------------------- | ---- | ------------------------ | 109| range | [TextRange](#textrange12)| Yes | Text range for which to obtain the area information. | 110| widthStyle | [RectWidthStyle](#rectwidthstyle14) | Yes | Width of the rectangle.| 111| heightStyle | [RectHeightStyle](#rectheightstyle14) | Yes | Height of the rectangle.| 112 113**Return value** 114 115| Type | Description | 116| --------------------------- | ----------- | 117| Array\<[TextBox](#textbox14)> | Array holding the rectangles obtained.| 118 119## PositionWithAffinity<sup>12+</sup> 120 121Describes the position and affinity of a glyph. 122 123**Atomic service API**: This API can be used in atomic services since API version 12. 124 125**System capability**: SystemCapability.ArkUI.ArkUI.Full 126 127| Name | Type | Read Only| Optional| Description | 128| --------- | --------------------- | ---- | ---- | ------------------------ | 129| position | number | Yes | No | Index of the glyph relative to the paragraph. The value is an integer. | 130| affinity | [Affinity](#affinity12) | Yes | Yes | Affinity of the position. | 131 132## TextMenuItemId<sup>12+</sup> 133 134Defines the unique identifier for a custom menu item. It is used to identify menu items. The IDs for built-in menu items are listed in the table below. 135 136**Atomic service API**: This API can be used in atomic services since API version 12. 137 138**System capability**: SystemCapability.ArkUI.ArkUI.Full 139 140### Properties 141 142**System capability**: SystemCapability.ArkUI.ArkUI.Full 143 144| Name | Type | Read Only | Optional | Description | 145| ------------ |---------------------| ---- | ---- | ------ | 146| CUT | [TextMenuItemId](#textmenuitemid12) | Yes | Yes| ID for the cut menu item.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 147| COPY | [TextMenuItemId](#textmenuitemid12) | Yes | Yes | ID for the paste menu item.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 148| PASTE | [TextMenuItemId](#textmenuitemid12) | Yes | Yes | ID for the paste menu item.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 149| SELECT_ALL | [TextMenuItemId](#textmenuitemid12) | Yes | Yes | ID for the select-all menu item.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 150| COLLABORATION_SERVICE | [TextMenuItemId](#textmenuitemid12) | Yes | Yes | ID for the collaboration service menu item.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 151| CAMERA_INPUT | [TextMenuItemId](#textmenuitemid12) | Yes | Yes | ID for the camera input menu item.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 152| AI_WRITER<sup>13+</sup> | [TextMenuItemId](#textmenuitemid12) | Yes | Yes | ID for the menu item involving text enhancement features, such as polishing, summary extraction, and formatting, for selected text. This menu item requires foundation model capabilities to function.<br>**Atomic service API**: This API can be used in atomic services since API version 13.| 153| TRANSLATE<sup>15+</sup> | [TextMenuItemId](#textmenuitemid12) | Yes | Yes | ID for the translate menu item.<br>**Atomic service API**: This API can be used in atomic services since API version 15.| 154| SHARE<sup>18+</sup> | [TextMenuItemId](#textmenuitemid12) | Yes | Yes | ID for the share menu item, which launches a window for sharing the selected text.<br>**Atomic service API**: This API can be used in atomic services since API version 18.| 155| SEARCH<sup>18+</sup> | [TextMenuItemId](#textmenuitemid12) | Yes | Yes | ID for the search menu item, which launches a browser to search the selected text.<br>**Atomic service API**: This API can be used in atomic services since API version 18.| 156 157### of 158 159static of(id: ResourceStr): TextMenuItemId 160 161Creates a **TextMenuItemId** object based on **id**. 162 163**Atomic service API**: This API can be used in atomic services since API version 12. 164 165**System capability**: SystemCapability.ArkUI.ArkUI.Full 166 167**Parameters** 168 169| Name | Type | Mandatory| Description | 170| ------- | --------------------------------- | ---- | ------------------------------------------------------------ | 171| id | [ResourceStr](ts-types.md#resourcestr) | Yes | Menu ID.| 172 173**Return value** 174 175| Type | Description | 176| ------- | --------------------------------- | 177| [TextMenuItemId](#textmenuitemid12) | **TextMenuItemId** object.| 178 179### equals 180 181equals(id: TextMenuItemId): boolean 182 183Checks whether this **TextMenuItemId** object is the same as another **TextMenuItemId** object. 184 185**Atomic service API**: This API can be used in atomic services since API version 12. 186 187**System capability**: SystemCapability.ArkUI.ArkUI.Full 188 189**Parameters** 190 191| Name | Type | Mandatory| Description | 192| ------- | --------------------------------- | ---- | ------------------------------------------------------------ | 193| id | [TextMenuItemId](#textmenuitemid12) | Yes | ID of the **TextMenuItemId** object to compare.| 194 195**Return value** 196 197| Type | Description | 198| ------- | --------------------------------- | 199| boolean | Whether the two **TextMenuItemId** objects are the same.| 200 201## TextMenuItem<sup>12+</sup> 202 203**Atomic service API**: This API can be used in atomic services since API version 12. 204 205**System capability**: SystemCapability.ArkUI.ArkUI.Full 206 207| Name | Type | Mandatory| Description | 208| ------- | --------------------------------- | ---- | --------------------------------- | 209| content | [ResourceStr](ts-types.md#resourcestr) | Yes | Menu name.| 210| icon | [ResourceStr](ts-types.md#resourcestr) | No | Menu icon.<br>Online images are not supported.| 211| id | [TextMenuItemId](#textmenuitemid12) | Yes | Menu ID.| 212| labelInfo<sup>15+</sup> | [ResourceStr](ts-types.md#resourcestr) | No | Shortcut key hint.<br>This field is only supported on 2-in-1 devices.<br>**Atomic service API**: This API can be used in atomic services since API version 15.| 213 214## EditMenuOptions 215 216**Atomic service API**: This API can be used in atomic services since API version 12. 217 218**System capability**: SystemCapability.ArkUI.ArkUI.Full 219 220### onCreateMenu<sup>12+</sup> 221 222onCreateMenu(menuItems: Array\<TextMenuItem>): Array\<TextMenuItem> 223 224Creates a menu with the specified menu items. 225 226**Atomic service API**: This API can be used in atomic services since API version 12. 227 228**System capability**: SystemCapability.ArkUI.ArkUI.Full 229 230**Parameters** 231 232| Name | Type | Mandatory| Description | 233| ------- | --------------------------------- | ---- | --------------------------------- | 234| menuItems | Array\<[TextMenuItem](#textmenuitem12)> | Yes | Menu items.<br>**NOTE**<br>Changes to the name of the default menu item do not take effect.| 235 236**Return value** 237 238| Type | Description | 239| ------- | --------------------------------- | 240| Array\<[TextMenuItem](#textmenuitem12)> | Menu items set.<br>**NOTE**<br>The icon of the default menu item is not returned.| 241 242### onMenuItemClick<sup>12+</sup> 243 244onMenuItemClick(menuItem: TextMenuItem, range: TextRange): boolean 245 246Called when the specified menu item is clicked. 247 248**Atomic service API**: This API can be used in atomic services since API version 12. 249 250**System capability**: SystemCapability.ArkUI.ArkUI.Full 251 252**Parameters** 253 254| Name | Type | Mandatory| Description | 255| ------- | --------------------------------- | ---- | --------------------------------- | 256| menuItem | [TextMenuItem](#textmenuitem12) | Yes | Menu item.| 257| range | [TextRange](#textrange12) | Yes | Selected text.| 258 259**Return value** 260 261| Type | Description | 262| ------- | --------------------------------- | 263| boolean | Execution logic of the menu item.<br>Returns **true** if the default system logic is intercepted and only the custom logic is executed.<br>Returns **false** if the custom logic is executed before the default system logic.| 264 265## TextRange<sup>12+</sup> 266 267Defines the text range. 268 269**Atomic service API**: This API can be used in atomic services since API version 12. 270 271**System capability**: SystemCapability.ArkUI.ArkUI.Full 272 273| Name| Type| Mandatory| Description| 274| -- | -- | -- | -- | 275| start | number | No| Start index.| 276| end | number | No| End index.| 277 278## EditableTextOnChangeCallback<sup>12+</sup> 279 280type EditableTextOnChangeCallback = (value: string, previewText?: PreviewText, options?: TextChangeOptions) => void 281 282Represents the callback triggered when the content in the text box changes. 283 284**Atomic service API**: This API can be used in atomic services since API version 12. 285 286**System capability**: SystemCapability.ArkUI.ArkUI.Full 287 288**Parameters** 289 290| Name| Type| Mandatory| Description| 291| -- | -- | -- | -- | 292| value | string | Yes| Text displayed in the text box.| 293| previewText | [PreviewText](#previewtext12) | No| Information about the preview text, including its start position and text content.| 294| options<sup>15+</sup> | [TextChangeOptions](#textchangeoptions15) | No| Information about the text change, including the selection range before and after the change, the text content before the change, and the preview text information.| 295 296## TextDataDetectorType<sup>11+</sup> 297 298**Atomic service API**: This API can be used in atomic services since API version 12. 299 300**System capability**: SystemCapability.ArkUI.ArkUI.Full 301 302| Name | Value | Description | 303| ----- | ----- | --------------------------------- | 304| PHONE_NUMBER | 0 | Phone number.| 305| URL | 1 | URL.| 306| EMAIL | 2 | Email address.| 307| ADDRESS | 3 | Address.| 308| DATE_TIME<sup>12+</sup> | 4 | Time.| 309 310## TextDeleteDirection<sup>12+</sup> 311 312Defines the direction for deleting text. 313 314**Atomic service API**: This API can be used in atomic services since API version 12. 315 316**System capability**: SystemCapability.ArkUI.ArkUI.Full 317 318| Name | Value | Description | 319| ------- | ---- | ---------------------------------- | 320| BACKWARD | 0 | Backward delete.| 321| FORWARD | 1 | Forward delete.| 322 323## MenuType<sup>13+</sup> 324 325Enumerates the menu types. 326 327**Atomic service API**: This API can be used in atomic services since API version 13. 328 329**System capability**: SystemCapability.ArkUI.ArkUI.Full 330 331| Name| Value| Description| 332| ------- | ---- | ------------------- | 333| SELECTION_MENU | 0 | Text selection menu.| 334| PREVIEW_MENU | 1 | Preview menu.| 335 336## KeyboardAppearance<sup>15+</sup> 337 338Enumerates the appearance modes of the keyboard. 339 340**Atomic service API**: This API can be used in atomic services since API version 15. 341 342**System capability**: SystemCapability.ArkUI.ArkUI.Full 343 344| Name| Value| Description| 345| ------- | ---- | ------------------- | 346| NONE_IMMERSIVE | 0 | Default appearance mode, not using immersive style.| 347| IMMERSIVE | 1 | Immersive style, following the system color mode.| 348| LIGHT_IMMERSIVE | 2 | Immersive style in light mode.| 349| DARK_IMMERSIVE | 3 | Immersive style in dark mode.| 350 351## InsertValue<sup>12+</sup> 352 353**Atomic service API**: This API can be used in atomic services since API version 12. 354 355**System capability**: SystemCapability.ArkUI.ArkUI.Full 356 357| Name | Type | Mandatory| Description | 358| ------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 359| insertOffset | number | Yes | Position of the inserted text.| 360| insertValue | string | Yes | Content of the inserted text.| 361 362## DeleteValue<sup>12+</sup> 363 364**Atomic service API**: This API can be used in atomic services since API version 12. 365 366**System capability**: SystemCapability.ArkUI.ArkUI.Full 367 368| Name | Type | Mandatory| Description | 369| ------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 370| deleteOffset | number | Yes | Position of the deleted text.| 371| direction | [TextDeleteDirection](#textdeletedirection12) | Yes | Direction for deleting the text.| 372| deleteValue | string | Yes | Content of the deleted text.| 373 374## TextDataDetectorConfig<sup>11+</sup> 375 376**Atomic service API**: This API can be used in atomic services since API version 12. 377 378**System capability**: SystemCapability.ArkUI.ArkUI.Full 379 380| Name| Type | Mandatory| Description | 381| ------ | -------- | ---- | ------------------------------------------- | 382| types | [TextDataDetectorType](ts-text-common.md#textdatadetectortype11)[] | Yes | Entity types for text recognition. Values **null** and **[]** indicate that all types of entities can be recognized.| 383| onDetectResultUpdate | (result: string) => void | No | Callback invoked when text recognition succeeds.<br>- **result**: text recognition result, in JSON format.| 384| color<sup>12+</sup> | [ResourceColor](ts-types.md#resourcecolor) | No | Entity color when text recognition succeeds.<br>Default value: **'#ff0a59f7'**| 385| decoration<sup>12+</sup> | [DecorationStyleInterface](ts-universal-styled-string.md#decorationstyleinterface)| No | Style of the entity decorative line when text recognition succeeds.<br>Default value:<br>{<br> type: TextDecorationType.Underline,<br> color: same as the entity<br> style: TextDecorationStyle.SOLID <br>} | 386 387## PreviewText<sup>12+</sup> 388 389Preview text. 390 391**Atomic service API**: This API can be used in atomic services since API version 12. 392 393**System capability**: SystemCapability.ArkUI.ArkUI.Full 394 395| Name | Type | Mandatory| Description | 396| -------- | ------------------------------------------------ | ---- | -------------------------------------------------------- | 397| offset | number | Yes | Start position of the preview text.| 398| value | string | Yes | Content of the preview text. | 399 400## FontSettingOptions<sup>12+</sup> 401 402Defines the font settings, including smooth and continuous adjustments for the font weight for components in your application. 403 404**Widget capability**: This API can be used in ArkTS widgets since API version 12. 405 406**Atomic service API**: This API can be used in atomic services since API version 12. 407 408**System capability**: SystemCapability.ArkUI.ArkUI.Full 409 410| Name | Type | Mandatory| Description | 411| -------- | ------------------------------------------------ | ---- | -------------------------------------------------------- | 412| enableVariableFontWeight | boolean | No | Whether to support variable font weight adjustment.<br>Default value: **false**.<br>**true**: Support variable font weight adjustment.<br>**false**: Do not support variable font weight adjustment.| 413 414## OnDidChangeCallback<sup>12+</sup> 415 416type OnDidChangeCallback = (rangeBefore: TextRange, rangeAfter: TextRange) => void 417 418Represents the callback invoked after text changes. 419 420**Atomic service API**: This API can be used in atomic services since API version 12. 421 422**System capability**: SystemCapability.ArkUI.ArkUI.Full 423 424**Parameters** 425 426| Name| Type| Mandatory| Description| 427| -- | -- | -- | -- | 428| rangeBefore | [TextRange](#textrange12) | Yes| Range of the text to be changed.| 429| rangeAfter | [TextRange](#textrange12) | Yes| Range of the text added.| 430 431## StyledStringChangedListener<sup>12+</sup> 432 433Defines the listener for changes of the styled string text content. 434 435**Atomic service API**: This API can be used in atomic services since API version 12. 436 437**System capability**: SystemCapability.ArkUI.ArkUI.Full 438 439| Name| Type| Mandatory| Description| 440| -- | -- | -- | -- | 441| onWillChange | Callback<[StyledStringChangeValue](#styledstringchangevalue12), boolean> | No| Callback invoked when text is about to change.| 442| onDidChange | [OnDidChangeCallback](#ondidchangecallback12) | No| Callback invoked when text is changed.| 443 444## StyledStringChangeValue<sup>12+</sup> 445 446Describes the text changes of the styled string. 447 448**Atomic service API**: This API can be used in atomic services since API version 12. 449 450**System capability**: SystemCapability.ArkUI.ArkUI.Full 451 452| Name| Type| Mandatory| Description| 453| -- | -- | -- | -- | 454| range | [TextRange](#textrange12) | Yes| Range of the styled string to be replaced in the original string.| 455| replacementString | [StyledString](ts-universal-styled-string.md#styledstring) | Yes| Styled string used for replacement.| 456| previewText | [StyledString](ts-universal-styled-string.md#styledstring) | No| Preview styled string.| 457 458## TextBaseController<sup>12+</sup> 459 460Defines a text selection controller. 461 462**Atomic service API**: This API can be used in atomic services since API version 12. 463 464**System capability**: SystemCapability.ArkUI.ArkUI.Full 465 466### setSelection<sup>12+</sup> 467 468setSelection(selectionStart: number, selectionEnd: number, options?: SelectionOptions): void 469 470Sets the range of content selection. The selected content is highlighted. 471 472If both **selectionStart** and **selectionEnd** are set to **-1**, the entire content is selected. 473 474The component must be focused for the API call to have effect. 475 476Since API version 12, on 2-in-1 devices, regardless of the value of **options**, calling the **setSelection** API will not display a menu; if a menu is already open, calling the API will close it. 477 478On non-2-in-1 devices, when **options** is set to **MenuPolicy.DEFAULT**, the following rules apply after the API is called: 479 4801. If the component has a menu with a selection handle, the menu remains open and is relocated according to the selection. 481 4822. If the component has a menu without a selection handle, the menu remains open and its position remains unchanged. 483 4843. If there is no menu open, no menu will appear after the selection. 485 486**Atomic service API**: This API can be used in atomic services since API version 12. 487 488**System capability**: SystemCapability.ArkUI.ArkUI.Full 489 490**Parameters** 491 492| Name | Type | Mandatory | Description | 493| -------------- | ------ | ---- | ------- | 494| selectionStart | number | Yes | Start position of the selection.<br>Values less than 0 are treated as **0**.| 495| selectionEnd | number | Yes | End position of the selection.<br>If the value exceeds the text length, the current text length is used instead.| 496| options | [SelectionOptions](ts-types.md#selectionoptions12) | No | Configuration of options.| 497 498### closeSelectionMenu<sup>12+</sup> 499 500closeSelectionMenu(): void 501 502Closes the custom or default text selection menu. 503 504**Atomic service API**: This API can be used in atomic services since API version 12. 505 506**System capability**: SystemCapability.ArkUI.ArkUI.Full 507 508### getLayoutManager<sup>12+</sup> 509 510getLayoutManager(): LayoutManager 511 512Obtains a **LayoutManager** object. 513 514**Atomic service API**: This API can be used in atomic services since API version 12. 515 516**System capability**: SystemCapability.ArkUI.ArkUI.Full 517 518**Return value** 519 520| Type | Description | 521| ---------------------------------------- | ------- | 522| [LayoutManager](ts-text-common.md#layoutmanager12) | Implements a **LayoutManager** object.| 523 524## TextEditControllerEx<sup>12+</sup> 525 526Implements an extended text editing controller. 527 528Inherits [TextBaseController](#textbasecontroller12). 529 530**Atomic service API**: This API can be used in atomic services since API version 12. 531 532**System capability**: SystemCapability.ArkUI.ArkUI.Full 533 534### isEditing<sup>12+</sup> 535 536isEditing(): boolean 537 538Obtains the editing status of the rich text. 539 540**Atomic service API**: This API can be used in atomic services since API version 12. 541 542**System capability**: SystemCapability.ArkUI.ArkUI.Full 543 544**Return value** 545 546| Type | Description | 547| ------- | ----------------------------- | 548| boolean | Editing status of the rich text. **true** means that the text is in editable state, and **false** means the opposite.| 549 550### stopEditing<sup>12+</sup> 551 552stopEditing(): void 553 554Stops editing. 555 556**Atomic service API**: This API can be used in atomic services since API version 12. 557 558**System capability**: SystemCapability.ArkUI.ArkUI.Full 559 560### getCaretOffset<sup>12+</sup> 561 562getCaretOffset(): number 563 564Obtains the current position of the cursor. 565 566**Atomic service API**: This API can be used in atomic services since API version 12. 567 568**System capability**: SystemCapability.ArkUI.ArkUI.Full 569 570**Return value** 571 572| Type | Description | 573| ------ | --------- | 574| number | Position of the cursor.| 575 576### setCaretOffset<sup>12+</sup> 577 578setCaretOffset(offset: number): boolean 579 580Sets the cursor offset. 581 582**Atomic service API**: This API can be used in atomic services since API version 12. 583 584**System capability**: SystemCapability.ArkUI.ArkUI.Full 585 586**Parameters** 587 588| Name | Type | Mandatory | Description | 589| ------ | ------ | ---- | -------------------- | 590| offset | number | Yes | Offset of the cursor. If the offset is outside the range of all content, the setting fails.| 591 592**Return value** 593 594| Type | Description | 595| ------- | --------- | 596| boolean | Whether the cursor is set successfully.| 597 598### getPreviewText<sup>12+</sup> 599 600getPreviewText?(): PreviewText 601 602Obtains the preview text. 603 604**Atomic service API**: This API can be used in atomic services since API version 12. 605 606**System capability**: SystemCapability.ArkUI.ArkUI.Full 607 608**Return value** 609 610| Type | Description | 611| ---------------------------------------- | ------- | 612| [PreviewText](#previewtext12) | Preview text.|. 613 614## StyledStringController<sup>12+</sup> 615 616Defines a styled string controller. 617 618**Atomic service API**: This API can be used in atomic services since API version 12. 619 620**System capability**: SystemCapability.ArkUI.ArkUI.Full 621 622### setStyledString<sup>12+</sup> 623 624setStyledString(styledString: StyledString): void 625 626Sets the styled string displayed in the rich text component. 627 628**Atomic service API**: This API can be used in atomic services since API version 12. 629 630**System capability**: SystemCapability.ArkUI.ArkUI.Full 631 632**Parameters** 633 634| Name | Type | Mandatory | Description | 635| ----- | ------ | ---- | ------------------- | 636| styledString | [StyledString](ts-universal-styled-string.md#styledstring) | Yes | Styled string to set.<br>**NOTE**<br>The child class [MutableStyledString](ts-universal-styled-string.md#mutablestyledstring) of **StyledString** can also serve as the argument.| 637 638### getStyledString<sup>12+</sup> 639 640getStyledString(): MutableStyledString 641 642Obtains the styled string displayed in the rich text component. 643 644**Atomic service API**: This API can be used in atomic services since API version 12. 645 646**System capability**: SystemCapability.ArkUI.ArkUI.Full 647 648**Return value** 649 650| Type | Description | 651| ------- | ----------------------------- | 652| [MutableStyledString](ts-universal-styled-string.md#mutablestyledstring) | Styled string displayed in the rich text component.| 653 654## DecorationStyleResult<sup>12+</sup> 655 656Provides the text decorative line information returned by the backend. 657 658**Atomic service API**: This API can be used in atomic services since API version 12. 659 660**System capability**: SystemCapability.ArkUI.ArkUI.Full 661 662| Name | Type | Mandatory| Description | 663| ------- | --------------------------------- | ---- | --------------------------------- | 664| type | [TextDecorationType](ts-appendix-enums.md#textdecorationtype) | Yes | Type of the text decorative line.| 665| color | [ResourceColor](ts-types.md#resourcecolor) | Yes | Color of the text decorative line.| 666| style | [TextDecorationStyle](ts-appendix-enums.md#textdecorationstyle12) | No | Style of the text decorative line.| 667 668## LineMetrics<sup>12+</sup> 669 670type LineMetrics = LineMetrics 671 672Describes the measurement information of a single line of text in the text layout. 673 674**Atomic service API**: This API can be used in atomic services since API version 12. 675 676**System capability**: SystemCapability.ArkUI.ArkUI.Full 677 678| Type | Description | 679| --------------------------------- | --------------------------------- | 680| [LineMetrics](../../apis-arkgraphics2d/js-apis-graphics-text.md#linemetrics) | Measurement information of a single line of text in the text layout.| 681 682## Affinity<sup>12+</sup> 683 684type Affinity = Affinity 685 686Enumerates the affinity modes. 687 688**Atomic service API**: This API can be used in atomic services since API version 12. 689 690**System capability**: SystemCapability.ArkUI.ArkUI.Full 691 692| Type | Description | 693| --------------------------------- | --------------------------------- | 694| [Affinity](../../apis-arkgraphics2d/js-apis-graphics-text.md#affinity) | Affinity mode enum.| 695 696## TextBox<sup>14+</sup> 697 698type TextBox = TextBox 699 700Describes the rectangle that holds the text. 701 702**Atomic service API**: This API can be used in atomic services since API version 14. 703 704**System capability**: SystemCapability.ArkUI.ArkUI.Full 705 706| Type | Description | 707| --------------------------------- | --------------------------------- | 708| [TextBox](../../apis-arkgraphics2d/js-apis-graphics-text.md#textbox) | Rectangle that holds the text.| 709 710## RectHeightStyle<sup>14+</sup> 711 712type RectHeightStyle = RectHeightStyle 713 714Enumerates the rectangle height styles. 715 716**Atomic service API**: This API can be used in atomic services since API version 14. 717 718**System capability**: SystemCapability.ArkUI.ArkUI.Full 719 720| Type | Description | 721| --------------------------------- | --------------------------------- | 722| [RectHeightStyle](../../apis-arkgraphics2d/js-apis-graphics-text.md#rectheightstyle) | Rectangle height style enum.| 723 724## RectWidthStyle<sup>14+</sup> 725 726type RectWidthStyle = RectWidthStyle 727 728Enumerates the rectangle width styles. 729 730**Atomic service API**: This API can be used in atomic services since API version 14. 731 732**System capability**: SystemCapability.ArkUI.ArkUI.Full 733 734| Type | Description | 735| --------------------------------- | --------------------------------- | 736| [RectWidthStyle](../../apis-arkgraphics2d/js-apis-graphics-text.md#rectwidthstyle) | Rectangle width style enum.| 737 738## TextChangeOptions<sup>15+</sup> 739 740Provides information about the text before and after a change, including the selection ranges. 741 742**Atomic service API**: This API can be used in atomic services since API version 15. 743 744**System capability**: SystemCapability.ArkUI.ArkUI.Full 745 746| Name | Type | Mandatory| Description | 747| ------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 748| rangeBefore | [TextRange](#textrange12) | Yes | Selection range before the change.| 749| rangeAfter | [TextRange](#textrange12) | Yes | Selection range after the change.| 750| oldContent | string | Yes | Text content before the change.| 751| oldPreviewText | [PreviewText](#previewtext12) | Yes| Preview text before the change.| 752 753## EditableTextChangeValue<sup>15+</sup> 754 755Provides detailed information of text changes, including preview text. 756 757**Atomic service API**: This API can be used in atomic services since API version 15. 758 759**System capability**: SystemCapability.ArkUI.ArkUI.Full 760 761| Name | Type | Mandatory| Description | 762| ------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 763| content | string | Yes | Current text content.| 764| previewText | [PreviewText](#previewtext12) | No | Preview text.| 765| options | [TextChangeOptions](#textchangeoptions15) | No | Information about the text change.| 766 767## TextMenuShowMode<sup>16+</sup> 768 769Enumerates the display modes for context menus on selection. 770 771**Atomic service API**: This API can be used in atomic services since API version 16. 772 773**System capability**: SystemCapability.ArkUI.ArkUI.Full 774 775| Name| Value| Description| 776| ------- | ---- | ------------------- | 777| DEFAULT | 0 | The menu is displayed in the current window.<br>| 778| PREFER_WINDOW | 1 | The menu is preferentially displayed in a separate window. If a separate window is not supported, the menu is displayed in the current window.<br>**NOTE**<br>The context menu on selection cannot be displayed in a separate window under the following scenarios:<br>Windows other than the main application window, application subwindows, system modal windows, and system home screen windows<br>DevEco Studio Previewer<br>UIExtension<br>Text component that is already displayed in a child window (for example, **Popup**, **Dialog**, **Toast**, and **Menu**)<br>**TextInput** or **TextArea** components that support **AutoFill**<br>| 779 780## TextMenuOptions<sup>16+</sup> 781 782Provides the options for customizing the context menu on selection. 783 784**Atomic service API**: This API can be used in atomic services since API version 16. 785 786**System capability**: SystemCapability.ArkUI.ArkUI.Full 787 788| Name | Type | Mandatory| Description | 789| ------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 790| showMode | [TextMenuShowMode](#textmenushowmode16) | No | Menu display mode.<br>Default value: **TextMenuShowMode.DEFAULT**| 791