• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.|
17| color  | [ResourceColor](ts-types.md#resourcecolor) | No  | Caret color.|
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 metrics information of a specified line.
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, starting at 0.|
88
89**Return value**
90
91| Type                                      | Description      |
92| ---------------------------------------- | -------- |
93| [LineMetrics](#linemetrics12) | Button("Line Metrics")|
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
134Provides the menu ID.
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### Attributes
141
142**System capability**: SystemCapability.ArkUI.ArkUI.Full
143
144| Name          | Type             | Read Only  | Optional | Description    |
145| ------------ |---------------------| ---- | ---- | ------ |
146| CUT  | [TextMenuItemId](#textmenuitemid12) |  Yes |  Yes| Default cut operation.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
147| COPY  | [TextMenuItemId](#textmenuitemid12) |  Yes |  Yes | Default copy operation.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
148| PASTE | [TextMenuItemId](#textmenuitemid12)   | Yes   | Yes   | Default paste operation.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
149| SELECT_ALL   | [TextMenuItemId](#textmenuitemid12)   | Yes   | Yes   | Default select-all operation.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
150| COLLABORATION_SERVICE   | [TextMenuItemId](#textmenuitemid12)   | Yes   | Yes   | Collaboration service.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
151| CAMERA_INPUT   | [TextMenuItemId](#textmenuitemid12)   | Yes   | Yes  | Camera input.<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   | 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   | Translation service.<br>**Atomic service API**: This API can be used in atomic services since API version 16.|
154
155### of
156
157static of(id: ResourceStr): TextMenuItemId
158
159Creates a **TextMenuItemId** object based on **id**.
160
161**Atomic service API**: This API can be used in atomic services since API version 12.
162
163**System capability**: SystemCapability.ArkUI.ArkUI.Full
164
165**Parameters**
166
167| Name | Type                             | Mandatory| Description                                                        |
168| ------- | --------------------------------- | ---- | ------------------------------------------------------------ |
169| id | [ResourceStr](ts-types.md#resourcestr) | Yes  | Menu ID.|
170
171**Return value**
172
173| Type             |       Description      |
174| ------- | --------------------------------- |
175| [TextMenuItemId](#textmenuitemid12) | **TextMenuItemId** object.|
176
177### equals
178
179equals(id: TextMenuItemId): boolean
180
181Checks whether this **TextMenuItemId** object is the same as another **TextMenuItemId** object.
182
183**Atomic service API**: This API can be used in atomic services since API version 12.
184
185**System capability**: SystemCapability.ArkUI.ArkUI.Full
186
187**Parameters**
188
189| Name | Type                             | Mandatory| Description                                                        |
190| ------- | --------------------------------- | ---- | ------------------------------------------------------------ |
191| id | [TextMenuItemId](#textmenuitemid12) | Yes  | ID of the **TextMenuItemId** object to compare.|
192
193**Return value**
194
195| Type             |       Description      |
196| ------- | --------------------------------- |
197| boolean | Whether the two **TextMenuItemId** objects are the same.|
198
199## TextMenuItem<sup>12+</sup>
200
201**Atomic service API**: This API can be used in atomic services since API version 12.
202
203**System capability**: SystemCapability.ArkUI.ArkUI.Full
204
205| Name | Type                             | Mandatory| Description  |
206| ------- | --------------------------------- | ---- | --------------------------------- |
207| content | [ResourceStr](ts-types.md#resourcestr) | Yes  | Menu name.|
208| icon | [ResourceStr](ts-types.md#resourcestr) | No  | Menu icon.<br>Online images are not supported.|
209| id | [TextMenuItemId](#textmenuitemid12) | Yes  | Menu ID.|
210| 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.|
211
212## EditMenuOptions
213
214**Atomic service API**: This API can be used in atomic services since API version 12.
215
216**System capability**: SystemCapability.ArkUI.ArkUI.Full
217
218### onCreateMenu<sup>12+</sup>
219
220onCreateMenu(menuItems: Array\<TextMenuItem>): Array\<TextMenuItem>
221
222Creates a menu with the specified menu items.
223
224**Atomic service API**: This API can be used in atomic services since API version 12.
225
226**System capability**: SystemCapability.ArkUI.ArkUI.Full
227
228**Parameters**
229
230| Name | Type                             | Mandatory| Description  |
231| ------- | --------------------------------- | ---- | --------------------------------- |
232| menuItems | Array\<[TextMenuItem](#textmenuitem12)> | Yes  | Menu items.<br>**NOTE**<br>Changes to the name of the default menu item do not take effect.|
233
234**Return value**
235
236| Type             |       Description      |
237| ------- | --------------------------------- |
238| Array\<[TextMenuItem](#textmenuitem12)> | Menu items set.<br>**NOTE**<br>The icon of the default menu item is not returned.|
239
240### onMenuItemClick<sup>12+</sup>
241
242onMenuItemClick(menuItem: TextMenuItem, range: TextRange): boolean
243
244Called when the specified menu item is clicked.
245
246**Atomic service API**: This API can be used in atomic services since API version 12.
247
248**System capability**: SystemCapability.ArkUI.ArkUI.Full
249
250**Parameters**
251
252| Name | Type                             | Mandatory| Description  |
253| ------- | --------------------------------- | ---- | --------------------------------- |
254| menuItem | [TextMenuItem](#textmenuitem12) | Yes  | Menu item.|
255| range | [TextRange](#textrange12) | Yes  | Selected text.|
256
257**Return value**
258
259| Type             |       Description      |
260| ------- | --------------------------------- |
261| 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.|
262
263## TextRange<sup>12+</sup>
264
265Defines the text range.
266
267**Atomic service API**: This API can be used in atomic services since API version 12.
268
269**System capability**: SystemCapability.ArkUI.ArkUI.Full
270
271| Name| Type| Mandatory| Description|
272| -- | -- | -- | -- |
273| start | number | No| Start index.|
274| end | number | No| End index.|
275
276## EditableTextOnChangeCallback<sup>12+</sup>
277
278type EditableTextOnChangeCallback = (value: string, previewText?: PreviewText, options?: TextChangeOptions) => void
279
280Represents the callback triggered when the content in the text box changes.
281
282**Atomic service API**: This API can be used in atomic services since API version 12.
283
284**System capability**: SystemCapability.ArkUI.ArkUI.Full
285
286**Parameters**
287
288| Name| Type| Mandatory| Description|
289| -- | -- | -- | -- |
290| value | string | Yes| Text displayed in the text box.|
291| previewText | [PreviewText](#previewtext12) | No| Information about the preview text, including its start position and text content.|
292| 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.|
293
294## TextDataDetectorType<sup>11+</sup>
295
296**Atomic service API**: This API can be used in atomic services since API version 12.
297
298**System capability**: SystemCapability.ArkUI.ArkUI.Full
299
300| Name | Value  | Description                              |
301| ----- | ----- | --------------------------------- |
302| PHONE_NUMBER  | 0 | Phone number.|
303| URL | 1 | URL.|
304| EMAIL | 2 | Email address.|
305| ADDRESS | 3 | Address.|
306| DATE_TIME<sup>12+</sup> | 4 | Time.|
307
308## TextDeleteDirection<sup>12+</sup>
309
310Defines the direction for deleting text.
311
312**Atomic service API**: This API can be used in atomic services since API version 12.
313
314**System capability**: SystemCapability.ArkUI.ArkUI.Full
315
316| Name   | Value  | Description                       |
317| ------- | ---- | ---------------------------------- |
318| BACKWARD | 0    | Backward delete.|
319| FORWARD    | 1    | Forward delete.|
320
321## MenuType<sup>13+</sup>
322
323Enumerates the menu types.
324
325**Atomic service API**: This API can be used in atomic services since API version 13.
326
327**System capability**: SystemCapability.ArkUI.ArkUI.Full
328
329| Name| Value| Description|
330| ------- | ---- | ------------------- |
331| SELECTION_MENU | 0 | Text selection menu.|
332| PREVIEW_MENU | 1 | Preview menu.|
333
334## KeyboardAppearance<sup>15+</sup>
335
336Enumerates the appearance modes of the keyboard.
337
338**Atomic service API**: This API can be used in atomic services since API version 16.
339
340**System capability**: SystemCapability.ArkUI.ArkUI.Full
341
342| Name| Value| Description|
343| ------- | ---- | ------------------- |
344| NONE_IMMERSIVE | 0 | Default appearance mode, not using immersive style.|
345| IMMERSIVE | 1 | Immersive style, following the system color mode.|
346| LIGHT_IMMERSIVE | 2 | Immersive style in light mode.|
347| DARK_IMMERSIVE | 3 | Immersive style in dark mode.|
348
349## InsertValue<sup>12+</sup>
350
351**Atomic service API**: This API can be used in atomic services since API version 12.
352
353**System capability**: SystemCapability.ArkUI.ArkUI.Full
354
355| Name   | Type                         | Mandatory| Description                                                        |
356| ------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
357| insertOffset  | number | Yes  | Position of the inserted text.|
358| insertValue  | string | Yes  | Content of the inserted text.|
359
360## DeleteValue<sup>12+</sup>
361
362**Atomic service API**: This API can be used in atomic services since API version 12.
363
364**System capability**: SystemCapability.ArkUI.ArkUI.Full
365
366| Name   | Type                                                   | Mandatory| Description                                                   |
367| ------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
368| deleteOffset  | number | Yes  | Position of the deleted text.|
369| direction  | [TextDeleteDirection](#textdeletedirection12) | Yes  | Direction for deleting the text.|
370| deleteValue  | string | Yes  | Content of the deleted text.|
371
372## TextDataDetectorConfig<sup>11+</sup>
373
374**Atomic service API**: This API can be used in atomic services since API version 12.
375
376**System capability**: SystemCapability.ArkUI.ArkUI.Full
377
378| Name| Type | Mandatory| Description |
379| ------ | -------- | ---- | ------------------------------------------- |
380| 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.|
381| onDetectResultUpdate   | (result: string) => void | No  | Callback invoked when text recognition succeeds.<br>- **result**: text recognition result, in JSON format.|
382| color<sup>12+</sup>   | [ResourceColor](ts-types.md#resourcecolor) | No  | Entity color when text recognition succeeds.<br>Default value: **'#ff0a59f7'**|
383| 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>} |
384
385## PreviewText<sup>12+</sup>
386
387Preview text.
388
389**Atomic service API**: This API can be used in atomic services since API version 12.
390
391**System capability**: SystemCapability.ArkUI.ArkUI.Full
392
393| Name    | Type                                            | Mandatory| Description                                                    |
394| -------- | ------------------------------------------------ | ---- | -------------------------------------------------------- |
395| offset | number | Yes  | Start position of the preview text.|
396| value    | string         | Yes  | Content of the preview text.        |
397
398## FontSettingOptions<sup>12+</sup>
399
400Defines the font settings, including smooth and continuous adjustments for the font weight for components in your application.
401
402**Widget capability**: This API can be used in ArkTS widgets since API version 12.
403
404**Atomic service API**: This API can be used in atomic services since API version 12.
405
406**System capability**: SystemCapability.ArkUI.ArkUI.Full
407
408| Name    | Type                                            | Mandatory| Description                                                    |
409| -------- | ------------------------------------------------ | ---- | -------------------------------------------------------- |
410| enableVariableFontWeight | boolean | No  | Whether to support variable font weight adjustment.<br>Default value: **false**|
411
412## OnDidChangeCallback<sup>12+</sup>
413
414type OnDidChangeCallback = (rangeBefore: TextRange, rangeAfter: TextRange) => void
415
416Represents the callback invoked after text changes.
417
418**Atomic service API**: This API can be used in atomic services since API version 12.
419
420**System capability**: SystemCapability.ArkUI.ArkUI.Full
421
422**Parameters**
423
424| Name| Type| Mandatory| Description|
425| -- | -- | -- | -- |
426| rangeBefore | [TextRange](#textrange12) | Yes| Range of the text to be changed.|
427| rangeAfter | [TextRange](#textrange12) | Yes| Range of the text added.|
428
429## StyledStringChangedListener<sup>12+</sup>
430
431Defines the listener for changes of the styled string text content.
432
433**Atomic service API**: This API can be used in atomic services since API version 12.
434
435**System capability**: SystemCapability.ArkUI.ArkUI.Full
436
437| Name| Type| Mandatory| Description|
438| -- | -- | -- | -- |
439| onWillChange | Callback<[StyledStringChangeValue](#styledstringchangevalue12), boolean> | No| Callback invoked when text is about to change.|
440| onDidChange | [OnDidChangeCallback](#ondidchangecallback12) | No| Callback invoked when text is changed.|
441
442## StyledStringChangeValue<sup>12+</sup>
443
444Describes the text changes of the styled string.
445
446**Atomic service API**: This API can be used in atomic services since API version 12.
447
448**System capability**: SystemCapability.ArkUI.ArkUI.Full
449
450| Name| Type| Mandatory| Description|
451| -- | -- | -- | -- |
452| range | TextRange | Yes| Range of the styled string to be replaced in the original string.|
453| replacementString | [StyledString](ts-universal-styled-string.md#styledstring) | Yes| Styled string used for replacement.|
454| previewText | [StyledString](ts-universal-styled-string.md#styledstring) | No| Preview styled string.|
455
456## TextBaseController<sup>12+</sup>
457
458Defines a text selection controller.
459
460**Atomic service API**: This API can be used in atomic services since API version 12.
461
462**System capability**: SystemCapability.ArkUI.ArkUI.Full
463
464### setSelection<sup>12+</sup>
465
466setSelection(selectionStart: number, selectionEnd: number, options?: SelectionOptions): void
467
468Sets the range of content selection. The selected content is highlighted.
469
470If both **selectionStart** and **selectionEnd** are set to **-1**, the entire content is selected.
471
472The component must be focused for the API call to have effect.
473
474Since 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.
475
476On non-2-in-1 devices, when **options** is set to **MenuPolicy.DEFAULT**, the following rules apply after the API is called:
477
4781. If the component has a menu with a selection handle, the menu remains open and is relocated according to the selection.
479
4802. If the component has a menu without a selection handle, the menu remains open and its position remains unchanged.
481
4823. If there is no menu open, no menu will appear after the selection.
483
484**Atomic service API**: This API can be used in atomic services since API version 12.
485
486**System capability**: SystemCapability.ArkUI.ArkUI.Full
487
488**Parameters**
489
490| Name           | Type  | Mandatory  | Description   |
491| -------------- | ------ | ---- | ------- |
492| selectionStart | number | Yes   | Start position of the selection.|
493| selectionEnd   | number | Yes   | End position of the selection.|
494| options   | [SelectionOptions](ts-types.md#selectionoptions12) | No   | Configuration of options.|
495
496### closeSelectionMenu<sup>12+</sup>
497
498closeSelectionMenu(): void
499
500Closes the custom or default text selection menu.
501
502**Atomic service API**: This API can be used in atomic services since API version 12.
503
504**System capability**: SystemCapability.ArkUI.ArkUI.Full
505
506### getLayoutManager<sup>12+</sup>
507
508getLayoutManager(): LayoutManager
509
510Obtains a **LayoutManager** object.
511
512**Atomic service API**: This API can be used in atomic services since API version 12.
513
514**System capability**: SystemCapability.ArkUI.ArkUI.Full
515
516**Return value**
517
518| Type                                      | Description     |
519| ---------------------------------------- | ------- |
520| [LayoutManager](ts-text-common.md#layoutmanager12) | Implements a **LayoutManager** object.|
521
522## TextEditControllerEx<sup>12+</sup>
523
524Implements an extended text editing controller.
525
526Inherits [TextBaseController](#textbasecontroller12).
527
528**Atomic service API**: This API can be used in atomic services since API version 12.
529
530**System capability**: SystemCapability.ArkUI.ArkUI.Full
531
532### isEditing<sup>12+</sup>
533
534isEditing(): boolean
535
536Obtains the editing status of the rich text.
537
538**Atomic service API**: This API can be used in atomic services since API version 12.
539
540**System capability**: SystemCapability.ArkUI.ArkUI.Full
541
542**Return value**
543
544| Type   | Description                         |
545| ------- | ----------------------------- |
546| boolean | Editing status of the rich text. **true** means that the text is in editable state, and **false** means the opposite.|
547
548### stopEditing<sup>12+</sup>
549
550stopEditing(): void
551
552Stops editing.
553
554**Atomic service API**: This API can be used in atomic services since API version 12.
555
556**System capability**: SystemCapability.ArkUI.ArkUI.Full
557
558### getCaretOffset<sup>12+</sup>
559
560getCaretOffset(): number
561
562Obtains the current position of the cursor.
563
564**Atomic service API**: This API can be used in atomic services since API version 12.
565
566**System capability**: SystemCapability.ArkUI.ArkUI.Full
567
568**Return value**
569
570| Type    | Description       |
571| ------ | --------- |
572| number | Position of the cursor.|
573
574### setCaretOffset<sup>12+</sup>
575
576setCaretOffset(offset: number): boolean
577
578Sets the cursor offset.
579
580**Atomic service API**: This API can be used in atomic services since API version 12.
581
582**System capability**: SystemCapability.ArkUI.ArkUI.Full
583
584**Parameters**
585
586| Name   | Type  | Mandatory  | Description               |
587| ------ | ------ | ---- | -------------------- |
588| offset | number | Yes   | Offset of the cursor. If the offset is outside the range of all content, the setting fails.|
589
590**Return value**
591
592| Type     | Description       |
593| ------- | --------- |
594| boolean | Whether the cursor is set successfully.|
595
596### getPreviewText<sup>12+</sup>
597
598getPreviewText?(): PreviewText
599
600Obtains the preview text.
601
602**Atomic service API**: This API can be used in atomic services since API version 12.
603
604**System capability**: SystemCapability.ArkUI.ArkUI.Full
605
606**Return value**
607
608| Type                                      | Description     |
609| ---------------------------------------- | ------- |
610| [PreviewText](#previewtext12) | Preview text.|.
611
612## StyledStringController<sup>12+</sup>
613
614Defines a styled string controller.
615
616**Atomic service API**: This API can be used in atomic services since API version 12.
617
618**System capability**: SystemCapability.ArkUI.ArkUI.Full
619
620### setStyledString<sup>12+</sup>
621
622setStyledString(styledString: StyledString): void
623
624Sets the styled string displayed in the rich text component.
625
626**Atomic service API**: This API can be used in atomic services since API version 12.
627
628**System capability**: SystemCapability.ArkUI.ArkUI.Full
629
630**Parameters**
631
632| Name  | Type  | Mandatory  | Description               |
633| ----- | ------ | ---- | ------------------- |
634| 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.|
635
636### getStyledString<sup>12+</sup>
637
638getStyledString(): MutableStyledString
639
640Obtains the styled string displayed in the rich text component.
641
642**Atomic service API**: This API can be used in atomic services since API version 12.
643
644**System capability**: SystemCapability.ArkUI.ArkUI.Full
645
646**Return value**
647
648| Type   | Description                         |
649| ------- | ----------------------------- |
650| [MutableStyledString](ts-universal-styled-string.md#mutablestyledstring) | Styled string displayed in the rich text component.|
651
652## DecorationStyleResult<sup>12+</sup>
653
654Provides the text decorative line information returned by the backend.
655
656**Atomic service API**: This API can be used in atomic services since API version 12.
657
658**System capability**: SystemCapability.ArkUI.ArkUI.Full
659
660| Name | Type                             | Mandatory| Description  |
661| ------- | --------------------------------- | ---- | --------------------------------- |
662| type | [TextDecorationType](ts-appendix-enums.md#textdecorationtype) | Yes  | Type of the text decorative line.|
663| color | [ResourceColor](ts-types.md#resourcecolor) | Yes  | Color of the text decorative line.|
664| style | [TextDecorationStyle](ts-appendix-enums.md#textdecorationstyle12) | No  | Style of the text decorative line.|
665
666## LineMetrics<sup>12+</sup>
667
668type LineMetrics = LineMetrics
669
670Describes the measurement information of a single line of text in the text layout.
671
672**Atomic service API**: This API can be used in atomic services since API version 12.
673
674**System capability**: SystemCapability.ArkUI.ArkUI.Full
675
676| Type                             | Description  |
677| --------------------------------- | --------------------------------- |
678| [LineMetrics](../../apis-arkgraphics2d/js-apis-graphics-text.md#linemetrics) | Measurement information of a single line of text in the text layout.|
679
680## Affinity<sup>12+</sup>
681
682type Affinity = Affinity
683
684Enumerates the affinity modes.
685
686**Atomic service API**: This API can be used in atomic services since API version 12.
687
688**System capability**: SystemCapability.ArkUI.ArkUI.Full
689
690| Type                             | Description  |
691| --------------------------------- | --------------------------------- |
692| [Affinity](../../apis-arkgraphics2d/js-apis-graphics-text.md#affinity) | Affinity mode enum.|
693
694## TextBox<sup>14+</sup>
695
696type TextBox = TextBox
697
698Describes the rectangle that holds the text.
699
700**Atomic service API**: This API can be used in atomic services since API version 14.
701
702**System capability**: SystemCapability.ArkUI.ArkUI.Full
703
704| Type                             | Description  |
705| --------------------------------- | --------------------------------- |
706| [TextBox](../../apis-arkgraphics2d/js-apis-graphics-text.md#textbox) | Rectangle that holds the text.|
707
708## RectHeightStyle<sup>14+</sup>
709
710type RectHeightStyle = RectHeightStyle
711
712Enumerates the rectangle height styles.
713
714**Atomic service API**: This API can be used in atomic services since API version 14.
715
716**System capability**: SystemCapability.ArkUI.ArkUI.Full
717
718| Type                             | Description  |
719| --------------------------------- | --------------------------------- |
720| [RectHeightStyle](../../apis-arkgraphics2d/js-apis-graphics-text.md#rectheightstyle) | Rectangle height style enum.|
721
722## RectWidthStyle<sup>14+</sup>
723
724type RectWidthStyle = RectWidthStyle
725
726Enumerates the rectangle width styles.
727
728**Atomic service API**: This API can be used in atomic services since API version 14.
729
730**System capability**: SystemCapability.ArkUI.ArkUI.Full
731
732| Type                             | Description  |
733| --------------------------------- | --------------------------------- |
734| [RectWidthStyle](../../apis-arkgraphics2d/js-apis-graphics-text.md#rectwidthstyle) | Rectangle width style enum.|
735
736## TextChangeOptions<sup>15+</sup>
737
738Provides information about the text before and after a change, including the selection ranges.
739
740**Atomic service API**: This API can be used in atomic services since API version 15.
741
742**System capability**: SystemCapability.ArkUI.ArkUI.Full
743
744| Name   | Type                                                   | Mandatory| Description                                                   |
745| ------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
746| rangeBefore  | [TextRange](#textrange12) | Yes  | Selection range before the change.|
747| rangeAfter  | [TextRange](#textrange12) | Yes  | Selection range after the change.|
748| oldContent  | string | Yes  | Text content before the change.|
749| oldPreviewText | [PreviewText](#previewtext12) | Yes| Preview text before the change.|
750
751## EditableTextChangeValue<sup>15+</sup>
752
753Provides detailed information of text changes, including preview text.
754
755**Atomic service API**: This API can be used in atomic services since API version 15.
756
757**System capability**: SystemCapability.ArkUI.ArkUI.Full
758
759| Name   | Type                                                   | Mandatory| Description                                                   |
760| ------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
761| content  | string | Yes  | Current text content.|
762| previewText  | [PreviewText](#previewtext12) | No  | Preview text.|
763| options  | [TextChangeOptions](#textchangeoptions15) | No  | Information about the text change.|
764
765