1# 文本组件公共接口 2 3>**说明:** 4> 5>文本类组件公共接口。 6>本模块首批接口从API version 10开始支持,后续版本的新增接口,采用上角标单独标记接口的起始版本。 7 8## CaretStyle<sup>10+</sup> 9 10**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 11 12**系统能力:** SystemCapability.ArkUI.ArkUI.Full 13 14| 名称 | 类型 | 必填 | 说明 | 15| ------ | ------------------------------------------ | ---- | -------- | 16| width | [Length](ts-types.md#length) | 否 | 光标尺寸,不支持百分比。 | 17| color | [ResourceColor](ts-types.md#resourcecolor) | 否 | 光标颜色。 | 18 19## LayoutManager<sup>12+</sup> 20 21布局管理器对象。 22 23> **说明:** 24> 25> 文本内容变更后,需等待布局完成才可获取到最新的布局信息。 26 27### 导入对象 28以Text组件为例 29``` 30controller: TextController = new TextController() 31let layoutManager: LayoutManager = this.controller.getLayoutManager(); 32``` 33 34### getLineCount 35 36getLineCount(): number 37 38获取组件内容的总行数。 39 40**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 41 42**系统能力:** SystemCapability.ArkUI.ArkUI.Full 43 44**返回值:** 45 46| 类型 | 说明 | 47| ------ | --------- | 48| number | 组件内容的总行数。 | 49 50### getGlyphPositionAtCoordinate 51 52getGlyphPositionAtCoordinate(x: number, y: number): PositionWithAffinity 53 54获取较为接近给定坐标的字形的位置信息。 55 56**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 57 58**系统能力:** SystemCapability.ArkUI.ArkUI.Full 59 60**参数:** 61 62| 参数名 | 类型 | 必填 | 说明 | 63| ------ | ------ | ---- | -------------------- | 64| x | number | 是 | 相对于组件的横坐标,单位px | 65| y | number | 是 | 相对于组件的纵坐标,单位px | 66 67**返回值:** 68 69| 类型 | 说明 | 70| --------------------------------------------- | ----------- | 71| [PositionWithAffinity](#positionwithaffinity12) | 字形位置信息。| 72 73### getLineMetrics 74 75getLineMetrics(lineNumber: number): LineMetrics 76 77获取指定行的行信息、文本样式信息、以及字体属性信息。 78 79**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 80 81**系统能力:** SystemCapability.ArkUI.ArkUI.Full 82 83**参数:** 84 85| 参数名 | 类型 | 必填 | 说明 | 86| ------ | ------ | ---- | -------------------- | 87| lineNumber | number | 是 | 行号。从0开始。 | 88 89**返回值:** 90 91| 类型 | 说明 | 92| ---------------------------------------- | -------- | 93| [LineMetrics](#linemetrics12) | 行信息、文本样式信息、以及字体属性信息。 | 94 95### getRectsForRange<sup>14+</sup> 96 97getRectsForRange(range: TextRange, widthStyle: RectWidthStyle, heightStyle: RectHeightStyle): Array\<TextBox> 98 99获取给定的矩形区域宽度以及矩形区域高度的规格下,文本中任意区间范围内的字符或占位符所占的绘制区域信息。 100 101**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 102 103**系统能力:** SystemCapability.ArkUI.ArkUI.Full 104 105**参数:** 106 107| 参数名 | 类型 | 必填 | 说明 | 108| ----------- | ----------------------------------- | ---- | ------------------------ | 109| range | [TextRange](#textrange12)| 是 | 需要获取的区域的文本区间。 | 110| widthStyle | [RectWidthStyle](#rectwidthstyle14) | 是 | 返回的矩形区域的宽度的规格。| 111| heightStyle | [RectHeightStyle](#rectheightstyle14) | 是 | 返回的矩形区域的高度的规格。| 112 113**返回值:** 114 115| 类型 | 说明 | 116| --------------------------- | ----------- | 117| Array\<[TextBox](#textbox14)> | 矩形区域数组。| 118 119## PositionWithAffinity<sup>12+</sup> 120 121位置以及亲和度。 122 123**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 124 125**系统能力:** SystemCapability.ArkUI.ArkUI.Full 126 127| 名称 | 类型 | 只读 | 可选 | 说明 | 128| --------- | --------------------- | ---- | ---- | ------------------------ | 129| position | number | 是 | 否 | 字形相对于组件内容的索引,整数。 | 130| affinity | [Affinity](#affinity12) | 是 | 是 | 位置亲和度。 | 131 132## TextMenuItemId<sup>12+</sup> 133 134菜单的Id值。 135 136**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 137 138**系统能力:** SystemCapability.ArkUI.ArkUI.Full 139 140### 属性 141 142**系统能力:** SystemCapability.ArkUI.ArkUI.Full 143 144| 名称 | 类型 | 只读 | 可选 | 说明 | 145| ------------ |---------------------| ---- | ---- | ------ | 146| CUT | [TextMenuItemId](#textmenuitemid12) | 是 | 是 | 默认裁剪。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 147| COPY | [TextMenuItemId](#textmenuitemid12) | 是 | 是 | 默认复制。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 148| PASTE | [TextMenuItemId](#textmenuitemid12) | 是 | 是 | 默认粘贴。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 149| SELECT_ALL | [TextMenuItemId](#textmenuitemid12) | 是 | 是 | 默认全选。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 150| COLLABORATION_SERVICE | [TextMenuItemId](#textmenuitemid12) | 是 | 是 | 互通服务。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 151| CAMERA_INPUT | [TextMenuItemId](#textmenuitemid12) | 是 | 是 | 拍摄输入。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 152| AI_WRITER<sup>13+</sup> | [TextMenuItemId](#textmenuitemid12) | 是 | 是 | 可对选中的文本进行润色、摘要提取、排版等。该菜单项依赖大模型能力,否则不生效。<br/>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 | 153 154### of 155 156static of(id: ResourceStr): TextMenuItemId 157 158根据id创建TextMenuItemId。 159 160**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 161 162**系统能力:** SystemCapability.ArkUI.ArkUI.Full 163 164**参数:** 165 166| 参数名 | 类型 | 必填 | 说明 | 167| ------- | --------------------------------- | ---- | ------------------------------------------------------------ | 168| id | [ResourceStr](ts-types.md#resourcestr) | 是 | 菜单的id。 | 169 170**返回值:** 171 172| 类型 | 说明 | 173| ------- | --------------------------------- | 174| [TextMenuItemId](#textmenuitemid12) | TextMenuItemId的对象。 | 175 176### equals 177 178equals(id: TextMenuItemId): boolean 179 180判断TextMenuItemId是否相等。 181 182**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 183 184**系统能力:** SystemCapability.ArkUI.ArkUI.Full 185 186**参数:** 187 188| 参数名 | 类型 | 必填 | 说明 | 189| ------- | --------------------------------- | ---- | ------------------------------------------------------------ | 190| id | [TextMenuItemId](#textmenuitemid12) | 是 | TextMenuItemId的id。 | 191 192**返回值:** 193 194| 类型 | 说明 | 195| ------- | --------------------------------- | 196| boolean | 两个TextMenuItemId是否相等。 | 197 198## TextMenuItem<sup>12+</sup>对象说明 199 200**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 201 202**系统能力:** SystemCapability.ArkUI.ArkUI.Full 203 204| 名称 | 类型 | 必填 | 说明 | 205| ------- | --------------------------------- | ---- | --------------------------------- | 206| content | [ResourceStr](ts-types.md#resourcestr) | 是 | 菜单名称。 | 207| icon | [ResourceStr](ts-types.md#resourcestr) | 否 | 菜单图标。<br/>不支持网络图片。 | 208| id | [TextMenuItemId](#textmenuitemid12) | 是 | 菜单id。 | 209 210## EditMenuOptions 211 212**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 213 214**系统能力:** SystemCapability.ArkUI.ArkUI.Full 215 216### onCreateMenu<sup>12+</sup> 217 218onCreateMenu(menuItems: Array\<TextMenuItem>): Array\<TextMenuItem> 219 220菜单数据模版编辑能力。 221 222**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 223 224**系统能力:** SystemCapability.ArkUI.ArkUI.Full 225 226**参数:** 227 228| 参数名 | 类型 | 必填 | 说明 | 229| ------- | --------------------------------- | ---- | --------------------------------- | 230| menuItems | Array<[TextMenuItem](#textmenuitem12对象说明)> | 是 | 菜单项。<br/>**说明:** <br/>对默认菜单项的名称修改不生效。 | 231 232**返回值:** 233 234| 类型 | 说明 | 235| ------- | --------------------------------- | 236| Array\<[TextMenuItem](#textmenuitem12对象说明)> | 设置的菜单项。<br/>**说明:** <br/>不返回系统默认菜单项的图标。 | 237 238### onMenuItemClick<sup>12+</sup> 239 240onMenuItemClick(menuItem: TextMenuItem, range: TextRange): boolean 241 242菜单项功能函数。 243 244**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 245 246**系统能力:** SystemCapability.ArkUI.ArkUI.Full 247 248**参数:** 249 250| 参数名 | 类型 | 必填 | 说明 | 251| ------- | --------------------------------- | ---- | --------------------------------- | 252| menuItem | [TextMenuItem](#textmenuitem12对象说明) | 是 | 菜单项。 | 253| range | [TextRange](#textrange12) | 是 | 选中的文本信息。 | 254 255**返回值:** 256 257| 类型 | 说明 | 258| ------- | --------------------------------- | 259| boolean | 菜单项的执行逻辑。<br/>返回为true,拦截系统默认逻辑,仅执行自定义逻辑。<br/>返回为false,先执行自定义逻辑,再执行系统逻辑。 | 260 261## TextRange<sup>12+</sup> 262 263文本范围。 264 265**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 266 267**系统能力:** SystemCapability.ArkUI.ArkUI.Full 268 269### 属性 270 271| 名称 | 类型 | 必填 | 说明 | 272| -- | -- | -- | -- | 273| start | number | 否 | 起始索引。 | 274| end | number | 否 | 结束索引。 | 275 276## EditableTextOnChangeCallback<sup>12+</sup> 277 278type EditableTextOnChangeCallback = (value: string, previewText?: PreviewText) => void 279 280输入内容发生变化时,触发该回调。 281 282**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 283 284**系统能力:** SystemCapability.ArkUI.ArkUI.Full 285 286**参数:** 287 288| 参数名 | 类型 | 必填 | 说明 | 289| -- | -- | -- | -- | 290| value | string | 是 | 文本框内正式上屏的文本内容。 | 291| previewText | [PreviewText](#previewtext12) | 否 | 预上屏文本信息,包含预上屏起始位置和文本内容。 | 292 293## TextDataDetectorType<sup>11+</sup>枚举说明 294 295**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 296 297**系统能力:** SystemCapability.ArkUI.ArkUI.Full 298 299| 名称 | 说明 | 300| ----- | -------------------------------------- | 301| PHONE_NUMBER | 电话号码 | 302| URL | 链接 | 303| EMAIL | 邮箱 | 304| ADDRESS | 地址 | 305| DATE_TIME<sup>12+</sup> | 时间 | 306 307## TextDeleteDirection<sup>12+</sup>枚举说明 308 309定义删除文本方向。 310 311**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 312 313**系统能力:** SystemCapability.ArkUI.ArkUI.Full 314 315| 名称 | 值 | 说明 | 316| ------- | ---- | ---------------------------------- | 317| BACKWARD | 0 | 向后删除。 | 318| FORWARD | 1 | 向前删除。 | 319 320## MenuType<sup>13+</sup>枚举说明 321 322菜单类型。 323 324**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 325 326**系统能力:** SystemCapability.ArkUI.ArkUI.Full 327 328| 名称 | 值 | 说明 | 329| ------- | ---- | ------------------- | 330| SELECTION_MENU | 0 | 文本选择菜单。| 331| PREVIEW_MENU | 1 | 图片预览菜单。| 332 333## InsertValue<sup>12+</sup>对象说明 334 335**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 336 337**系统能力:** SystemCapability.ArkUI.ArkUI.Full 338 339| 名称 | 类型 | 必填 | 说明 | 340| ------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 341| insertOffset | number | 是 | 插入的值的位置信息。 | 342| insertValue | string | 是 | 插入的值。 | 343 344## DeleteValue<sup>12+</sup>对象说明 345 346**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 347 348**系统能力:** SystemCapability.ArkUI.ArkUI.Full 349 350| 名称 | 类型 | 必填 | 说明 | 351| ------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 352| deleteOffset | number | 是 | 删除的值的位置信息。 | 353| direction | [TextDeleteDirection](#textdeletedirection12枚举说明) | 是 | 删除值的方向。 | 354| deleteValue | string | 是 | 删除的值。 | 355 356## TextDataDetectorConfig<sup>11+</sup>对象说明 357 358**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 359 360**系统能力:** SystemCapability.ArkUI.ArkUI.Full 361 362| 名称 | 类型 | 必填 | 说明 | 363| ------ | -------- | ---- | ------------------------------------------- | 364| types | [TextDataDetectorType](ts-text-common.md#textdatadetectortype11枚举说明)[] | 是 | 设置文本识别的实体类型。设置types为null或者[]时,识别所有类型的实体,否则只识别指定类型的实体。 | 365| onDetectResultUpdate | (result: string) => void | 否 | 文本识别成功后,触发onDetectResultUpdate回调。<br/>- result:文本识别的结果,Json格式。 | 366| color<sup>12+</sup> | [ResourceColor](ts-types.md#resourcecolor) | 否 | 设置文本识别成功后的实体颜色。<br/>默认值:'#ff0a59f7' | 367| decoration<sup>12+</sup> | [DecorationStyleInterface](ts-universal-styled-string.md#decorationstyleinterface对象说明)| 否 | 设置文本识别成功后的实体装饰线样式。<br/>默认值:<br/>{<br/> type: TextDecorationType.Underline,<br/> color: 与实体颜色一致,<br/> style: TextDecorationStyle.SOLID <br/>} | 368## PreviewText<sup>12+</sup> 369 370预上屏信息。 371 372**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 373 374**系统能力:** SystemCapability.ArkUI.ArkUI.Full 375 376| 名称 | 类型 | 必填 | 说明 | 377| -------- | ------------------------------------------------ | ---- | -------------------------------------------------------- | 378| offset | number | 是 | 预上屏内容的起始位置。 | 379| value | string | 是 | 预上屏的内容。 | 380 381## FontSettingOptions<sup>12+</sup>对象说明 382 383字体配置项,比如通过设置应用内组件的字体粗细,进行字体粗细的无极调节(指在一定范围内无限制的调节的状态)。 384 385**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 386 387**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 388 389**系统能力:** SystemCapability.ArkUI.ArkUI.Full 390 391| 名称 | 类型 | 必填 | 说明 | 392| -------- | ------------------------------------------------ | ---- | -------------------------------------------------------- | 393| enableVariableFontWeight | boolean | 否 | 是否支持字重无极调节。<br/>默认值:false | 394 395## OnDidChangeCallback<sup>12+</sup> 396 397type OnDidChangeCallback = (rangeBefore: TextRange, rangeAfter: TextRange) => void 398 399文本变换后回调。 400 401**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 402 403**系统能力:** SystemCapability.ArkUI.ArkUI.Full 404 405**参数:** 406 407| 参数名 | 类型 | 必填 | 说明 | 408| -- | -- | -- | -- | 409| rangeBefore | [TextRange](#textrange12) | 是 | 文本变化前将要被替换的文本范围。 | 410| rangeAfter | [TextRange](#textrange12) | 是 | 文本变化后新增内容的文本范围。 | 411 412## StyledStringChangedListener<sup>12+</sup> 413 414属性字符串的文本内容变化监听器。 415 416**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 417 418**系统能力:** SystemCapability.ArkUI.ArkUI.Full 419 420| 名称 | 类型 | 必填 | 说明 | 421| -- | -- | -- | -- | 422| onWillChange | Callback<[StyledStringChangeValue](ts-basic-components-richeditor.md#styledstringchangevalue12), boolean> | 否 | 文本内容将要变化回调函数。 | 423| onDidChange | [OnDidChangeCallback](#ondidchangecallback12) | 否 | 文本内容完成变化回调函数。 | 424 425## StyledStringChangeValue<sup>12+</sup> 426 427属性字符串的文本变化信息。 428 429**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 430 431**系统能力:** SystemCapability.ArkUI.ArkUI.Full 432 433| 名称 | 类型 | 必填 | 说明 | 434| -- | -- | -- | -- | 435| range | TextRange | 是 | 即将被替换的属性字符串子串在原字符串中的范围。 | 436| replacementString | [StyledString](ts-universal-styled-string.md#styledstring) | 是 | 用于替换的属性字符串。 | 437| previewText | [StyledString](ts-universal-styled-string.md#styledstring) | 否 | 预览样式字符串。 | 438 439## TextBaseController<sup>12+</sup> 440 441文本选择控制器。 442 443**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 444 445**系统能力:** SystemCapability.ArkUI.ArkUI.Full 446 447### setSelection<sup>12+</sup> 448 449setSelection(selectionStart: number, selectionEnd: number, options?: SelectionOptions): void 450 451支持设置组件内的内容选中,选中部分背板高亮。 452 453selectionStart和selectionEnd均为-1时表示全选。 454 455未获焦时调用该接口不产生选中效果。 456 457从API version 12开始,在2in1设备中,无论options取何值,调用setSelection接口都不会弹出菜单,此外,如果组件中已经存在菜单,调用setSelection接口会关闭菜单。 458 459在非2in1设备中,options取值为MenuPolicy.DEFAULT时,遵循以下规则: 460 4611. 组件内有手柄菜单时,接口调用后不关闭菜单,并且调整菜单位置。 462 4632. 组件内有不带手柄的菜单时,接口调用后不关闭菜单,并且菜单位置不变。 464 4653. 组件内无菜单时,接口调用后也无菜单显示。 466 467**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 468 469**系统能力:** SystemCapability.ArkUI.ArkUI.Full 470 471**参数:** 472 473| 参数名 | 类型 | 必填 | 说明 | 474| -------------- | ------ | ---- | ------- | 475| selectionStart | number | 是 | 选中开始位置。 | 476| selectionEnd | number | 是 | 选中结束位置。 | 477| options<sup>12+</sup> | [SelectionOptions](ts-types.md#selectionoptions12对象说明) | 否 | 选择项配置。 | 478 479### closeSelectionMenu<sup>12+</sup> 480 481closeSelectionMenu(): void 482 483关闭自定义选择菜单或系统默认选择菜单。 484 485**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 486 487**系统能力:** SystemCapability.ArkUI.ArkUI.Full 488 489### getLayoutManager<sup>12+</sup> 490 491getLayoutManager(): LayoutManager 492 493获取布局管理器对象。 494 495**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 496 497**系统能力:** SystemCapability.ArkUI.ArkUI.Full 498 499**返回值:** 500 501| 类型 | 说明 | 502| ---------------------------------------- | ------- | 503| [LayoutManager](ts-text-common.md#layoutmanager12) | 布局管理器对象。 | 504 505## TextEditControllerEx<sup>12+</sup> 506 507文本扩展编辑控制器。 508 509继承自[TextBaseController](#textbasecontroller12)。 510 511**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 512 513**系统能力:** SystemCapability.ArkUI.ArkUI.Full 514 515### isEditing<sup>12+</sup> 516 517isEditing(): boolean 518 519获取当前富文本的编辑状态。 520 521**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 522 523**系统能力:** SystemCapability.ArkUI.ArkUI.Full 524 525**返回值:** 526 527| 类型 | 说明 | 528| ------- | ----------------------------- | 529| boolean | true为编辑态,false为非编辑态。 | 530 531### stopEditing<sup>12+</sup> 532 533stopEditing(): void 534 535退出编辑态。 536 537**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 538 539**系统能力:** SystemCapability.ArkUI.ArkUI.Full 540 541### getCaretOffset<sup>12+</sup> 542 543getCaretOffset(): number 544 545返回当前光标所在位置。 546 547**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 548 549**系统能力:** SystemCapability.ArkUI.ArkUI.Full 550 551**返回值:** 552 553| 类型 | 说明 | 554| ------ | --------- | 555| number | 当前光标所在位置。 | 556 557### setCaretOffset<sup>12+</sup> 558 559setCaretOffset(offset: number): boolean 560 561设置光标位置。 562 563**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 564 565**系统能力:** SystemCapability.ArkUI.ArkUI.Full 566 567**参数:** 568 569| 参数名 | 类型 | 必填 | 说明 | 570| ------ | ------ | ---- | -------------------- | 571| offset | number | 是 | 光标偏移位置。超出所有内容范围时,设置失败。 | 572 573**返回值:** 574 575| 类型 | 说明 | 576| ------- | --------- | 577| boolean | 光标是否设置成功。 | 578 579### getPreviewText<sup>12+</sup> 580 581getPreviewText?(): PreviewText 582 583获取预上屏信息。 584 585**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 586 587**系统能力:** SystemCapability.ArkUI.ArkUI.Full 588 589**返回值:** 590 591| 类型 | 说明 | 592| ---------------------------------------- | ------- | 593| [PreviewText](#previewtext12) | 预上屏信息。 |. 594 595## StyledStringController<sup>12+</sup> 596 597定义StyledString控制器。 598 599**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 600 601**系统能力:** SystemCapability.ArkUI.ArkUI.Full 602 603### setStyledString<sup>12+</sup> 604 605setStyledString(styledString: StyledString): void 606 607设置富文本组件显示的属性字符串。 608 609**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 610 611**系统能力:** SystemCapability.ArkUI.ArkUI.Full 612 613**参数:** 614 615| 参数名 | 类型 | 必填 | 说明 | 616| ----- | ------ | ---- | ------------------- | 617| styledString | [StyledString](ts-universal-styled-string.md#styledstring) | 是 | 属性字符串。<br/>**说明:** <br/>StyledString的子类[MutableStyledString](ts-universal-styled-string.md#mutablestyledstring)也可以作为入参值。 | 618 619### getStyledString<sup>12+</sup> 620 621getStyledString(): MutableStyledString; 622 623获取富文本组件显示的属性字符串。 624 625**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 626 627**系统能力:** SystemCapability.ArkUI.ArkUI.Full 628 629**返回值:** 630 631| 类型 | 说明 | 632| ------- | ----------------------------- | 633| [MutableStyledString](ts-universal-styled-string.md#mutablestyledstring) | 富文本组件显示的属性字符串 | 634 635## DecorationStyleResult<sup>12+</sup> 636 637后端返回的文本装饰线样式信息。 638 639**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 640 641**系统能力:** SystemCapability.ArkUI.ArkUI.Full 642 643| 名称 | 类型 | 必填 | 说明 | 644| ------- | --------------------------------- | ---- | --------------------------------- | 645| type | [TextDecorationType](ts-appendix-enums.md#textdecorationtype) | 是 | 装饰线类型。 | 646| color | [ResourceColor](ts-types.md#resourcecolor) | 是 | 装饰线颜色。 | 647| style | [TextDecorationStyle](ts-appendix-enums.md#textdecorationstyle12) | 否 | 装饰线样式。 | 648 649## LineMetrics<sup>12+</sup> 650 651type LineMetrics = LineMetrics 652 653用于描述文本布局中单行文字的度量信息。 654 655**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 656 657**系统能力:** SystemCapability.ArkUI.ArkUI.Full 658 659| 类型 | 说明 | 660| --------------------------------- | --------------------------------- | 661| [LineMetrics](../../apis-arkgraphics2d/js-apis-graphics-text.md#linemetrics) | 用于描述文本布局中单行文字的度量信息。 | 662 663## Affinity<sup>12+</sup> 664 665type Affinity = Affinity 666 667位置亲和度枚举。 668 669**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 670 671**系统能力:** SystemCapability.ArkUI.ArkUI.Full 672 673| 类型 | 说明 | 674| --------------------------------- | --------------------------------- | 675| [Affinity](../../apis-arkgraphics2d/js-apis-graphics-text.md#affinity) | 位置亲和度枚举。 | 676 677## TextBox<sup>14+</sup> 678 679type TextBox = TextBox 680 681文本矩形区域。 682 683**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 684 685**系统能力:** SystemCapability.ArkUI.ArkUI.Full 686 687| 类型 | 说明 | 688| --------------------------------- | --------------------------------- | 689| [TextBox](../../apis-arkgraphics2d/js-apis-graphics-text.md#textbox) | 文本矩形区域。 | 690 691## RectHeightStyle<sup>14+</sup> 692 693type RectHeightStyle = RectHeightStyle 694 695矩形区域高度规格枚举。 696 697**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 698 699**系统能力:** SystemCapability.ArkUI.ArkUI.Full 700 701| 类型 | 说明 | 702| --------------------------------- | --------------------------------- | 703| [RectHeightStyle](../../apis-arkgraphics2d/js-apis-graphics-text.md#rectheightstyle) | 矩形区域高度规格枚举。 | 704 705## RectWidthStyle<sup>14+</sup> 706 707type RectWidthStyle = RectWidthStyle 708 709矩形区域宽度规格枚举。 710 711**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 712 713**系统能力:** SystemCapability.ArkUI.ArkUI.Full 714 715| 类型 | 说明 | 716| --------------------------------- | --------------------------------- | 717| [RectWidthStyle](../../apis-arkgraphics2d/js-apis-graphics-text.md#rectwidthstyle) | 矩形区域宽度规格枚举。 |