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) | 否 | 光标尺寸,不支持百分比。<br/>默认值:'2vp' | 17| color | [ResourceColor](ts-types.md#resourcecolor) | 否 | 光标颜色。<br/>默认值:'#ff007dff' | 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 | 是 | 相对于组件的横坐标。<br/>单位:px | 65| y | number | 是 | 相对于组件的纵坐标。<br/>单位: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) | 行信息、文本样式信息、以及字体属性信息。<br/>当行号小于0或超出实际行,返回无效值。 | 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| TRANSLATE<sup>15+</sup> | [TextMenuItemId](#textmenuitemid12) | 是 | 是 | 对选中的文本提供翻译服务。<br/>**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 | 154 155### of 156 157static of(id: ResourceStr): TextMenuItemId 158 159根据id创建TextMenuItemId。 160 161**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 162 163**系统能力:** SystemCapability.ArkUI.ArkUI.Full 164 165**参数:** 166 167| 参数名 | 类型 | 必填 | 说明 | 168| ------- | --------------------------------- | ---- | ------------------------------------------------------------ | 169| id | [ResourceStr](ts-types.md#resourcestr) | 是 | 菜单的id。 | 170 171**返回值:** 172 173| 类型 | 说明 | 174| ------- | --------------------------------- | 175| [TextMenuItemId](#textmenuitemid12) | TextMenuItemId的对象。 | 176 177### equals 178 179equals(id: TextMenuItemId): boolean 180 181判断TextMenuItemId是否相等。 182 183**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 184 185**系统能力:** SystemCapability.ArkUI.ArkUI.Full 186 187**参数:** 188 189| 参数名 | 类型 | 必填 | 说明 | 190| ------- | --------------------------------- | ---- | ------------------------------------------------------------ | 191| id | [TextMenuItemId](#textmenuitemid12) | 是 | TextMenuItemId的id。 | 192 193**返回值:** 194 195| 类型 | 说明 | 196| ------- | --------------------------------- | 197| boolean | 两个TextMenuItemId是否相等。 | 198 199## TextMenuItem<sup>12+</sup>对象说明 200 201**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 202 203**系统能力:** SystemCapability.ArkUI.ArkUI.Full 204 205| 名称 | 类型 | 必填 | 说明 | 206| ------- | --------------------------------- | ---- | --------------------------------- | 207| content | [ResourceStr](ts-types.md#resourcestr) | 是 | 菜单名称。 | 208| icon | [ResourceStr](ts-types.md#resourcestr) | 否 | 菜单图标。<br/>不支持网络图片。 | 209| id | [TextMenuItemId](#textmenuitemid12) | 是 | 菜单id。 | 210| labelInfo<sup>15+</sup> | [ResourceStr](ts-types.md#resourcestr) | 否 | 快捷键提示。<br/>该字段仅2in1设备支持。<br/>**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 | 211 212## EditMenuOptions 213 214**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 215 216**系统能力:** SystemCapability.ArkUI.ArkUI.Full 217 218### onCreateMenu<sup>12+</sup> 219 220onCreateMenu(menuItems: Array\<TextMenuItem>): Array\<TextMenuItem> 221 222菜单数据模版编辑能力。 223 224**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 225 226**系统能力:** SystemCapability.ArkUI.ArkUI.Full 227 228**参数:** 229 230| 参数名 | 类型 | 必填 | 说明 | 231| ------- | --------------------------------- | ---- | --------------------------------- | 232| menuItems | Array<[TextMenuItem](#textmenuitem12对象说明)> | 是 | 菜单项。<br/>**说明:** <br/>对默认菜单项的名称修改不生效。 | 233 234**返回值:** 235 236| 类型 | 说明 | 237| ------- | --------------------------------- | 238| Array\<[TextMenuItem](#textmenuitem12对象说明)> | 设置的菜单项。<br/>**说明:** <br/>不返回系统默认菜单项的图标。 | 239 240### onMenuItemClick<sup>12+</sup> 241 242onMenuItemClick(menuItem: TextMenuItem, range: TextRange): boolean 243 244菜单项功能函数。 245 246**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 247 248**系统能力:** SystemCapability.ArkUI.ArkUI.Full 249 250**参数:** 251 252| 参数名 | 类型 | 必填 | 说明 | 253| ------- | --------------------------------- | ---- | --------------------------------- | 254| menuItem | [TextMenuItem](#textmenuitem12对象说明) | 是 | 菜单项。 | 255| range | [TextRange](#textrange12) | 是 | 选中的文本信息。 | 256 257**返回值:** 258 259| 类型 | 说明 | 260| ------- | --------------------------------- | 261| boolean | 菜单项的执行逻辑。<br/>返回为true,拦截系统默认逻辑,仅执行自定义逻辑。<br/>返回为false,先执行自定义逻辑,再执行系统逻辑。 | 262 263## TextRange<sup>12+</sup> 264 265文本范围。 266 267**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 268 269**系统能力:** SystemCapability.ArkUI.ArkUI.Full 270 271| 名称 | 类型 | 必填 | 说明 | 272| -- | -- | -- | -- | 273| start | number | 否 | 起始索引。 | 274| end | number | 否 | 结束索引。 | 275 276## EditableTextOnChangeCallback<sup>12+</sup> 277 278type EditableTextOnChangeCallback = (value: string, previewText?: PreviewText, options?: TextChangeOptions) => 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| options<sup>15+</sup> | [TextChangeOptions](#textchangeoptions15对象说明) | 否 | 文本内容变化信息,包含变化前后的选区范围、变化前的文本内容和预上屏文本信息。 | 293 294## TextDataDetectorType<sup>11+</sup>枚举说明 295 296**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 297 298**系统能力:** SystemCapability.ArkUI.ArkUI.Full 299 300| 名称 | 值 | 说明 | 301| ----- | ----- | --------------------------------- | 302| PHONE_NUMBER | 0 | 电话号码 | 303| URL | 1 | 链接 | 304| EMAIL | 2 | 邮箱 | 305| ADDRESS | 3 | 地址 | 306| DATE_TIME<sup>12+</sup> | 4 | 时间 | 307 308## TextDeleteDirection<sup>12+</sup>枚举说明 309 310定义删除文本方向。 311 312**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 313 314**系统能力:** SystemCapability.ArkUI.ArkUI.Full 315 316| 名称 | 值 | 说明 | 317| ------- | ---- | ---------------------------------- | 318| BACKWARD | 0 | 向后删除。 | 319| FORWARD | 1 | 向前删除。 | 320 321## MenuType<sup>13+</sup>枚举说明 322 323菜单类型。 324 325**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 326 327**系统能力:** SystemCapability.ArkUI.ArkUI.Full 328 329| 名称 | 值 | 说明 | 330| ------- | ---- | ------------------- | 331| SELECTION_MENU | 0 | 文本选择菜单。| 332| PREVIEW_MENU | 1 | 图片预览菜单。| 333 334## KeyboardAppearance<sup>15+</sup>枚举说明 335 336键盘外观。 337 338**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 339 340**系统能力:** SystemCapability.ArkUI.ArkUI.Full 341 342| 名称 | 值 | 说明 | 343| ------- | ---- | ------------------- | 344| NONE_IMMERSIVE | 0 | 默认外观模式,不采用沉浸式风格。| 345| IMMERSIVE | 1 | 沉浸式模式,跟随系统。| 346| LIGHT_IMMERSIVE | 2 | 浅色沉浸式风格。| 347| DARK_IMMERSIVE | 3 | 深色沉浸式风格。| 348 349## InsertValue<sup>12+</sup>对象说明 350 351**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 352 353**系统能力:** SystemCapability.ArkUI.ArkUI.Full 354 355| 名称 | 类型 | 必填 | 说明 | 356| ------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 357| insertOffset | number | 是 | 插入的值的位置信息。 | 358| insertValue | string | 是 | 插入的值。 | 359 360## DeleteValue<sup>12+</sup>对象说明 361 362**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 363 364**系统能力:** SystemCapability.ArkUI.ArkUI.Full 365 366| 名称 | 类型 | 必填 | 说明 | 367| ------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 368| deleteOffset | number | 是 | 删除的值的位置信息。 | 369| direction | [TextDeleteDirection](#textdeletedirection12枚举说明) | 是 | 删除值的方向。 | 370| deleteValue | string | 是 | 删除的值。 | 371 372## TextDataDetectorConfig<sup>11+</sup>对象说明 373 374**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 375 376**系统能力:** SystemCapability.ArkUI.ArkUI.Full 377 378| 名称 | 类型 | 必填 | 说明 | 379| ------ | -------- | ---- | ------------------------------------------- | 380| types | [TextDataDetectorType](ts-text-common.md#textdatadetectortype11枚举说明)[] | 是 | 设置文本识别的实体类型。设置types为null或者[]时,识别所有类型的实体,否则只识别指定类型的实体。 | 381| onDetectResultUpdate | (result: string) => void | 否 | 文本识别成功后,触发onDetectResultUpdate回调。<br/>- result:文本识别的结果,Json格式。 | 382| color<sup>12+</sup> | [ResourceColor](ts-types.md#resourcecolor) | 否 | 设置文本识别成功后的实体颜色。<br/>默认值:'#ff0a59f7' | 383| decoration<sup>12+</sup> | [DecorationStyleInterface](ts-universal-styled-string.md#decorationstyleinterface对象说明)| 否 | 设置文本识别成功后的实体装饰线样式。<br/>默认值:<br/>{<br/> type: TextDecorationType.Underline,<br/> color: 与实体颜色一致,<br/> style: TextDecorationStyle.SOLID <br/>} | 384 385## PreviewText<sup>12+</sup> 386 387预上屏信息。 388 389**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 390 391**系统能力:** SystemCapability.ArkUI.ArkUI.Full 392 393| 名称 | 类型 | 必填 | 说明 | 394| -------- | ------------------------------------------------ | ---- | -------------------------------------------------------- | 395| offset | number | 是 | 预上屏内容的起始位置。 | 396| value | string | 是 | 预上屏的内容。 | 397 398## FontSettingOptions<sup>12+</sup>对象说明 399 400字体配置项,比如通过设置应用内组件的字体粗细,进行字体粗细的无极调节(指在一定范围内无限制的调节的状态)。 401 402**卡片能力:** 从API version 12开始,该接口支持在ArkTS卡片中使用。 403 404**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 405 406**系统能力:** SystemCapability.ArkUI.ArkUI.Full 407 408| 名称 | 类型 | 必填 | 说明 | 409| -------- | ------------------------------------------------ | ---- | -------------------------------------------------------- | 410| enableVariableFontWeight | boolean | 否 | 是否支持字重无极调节。<br/>默认值:false<br/>值为true,表示支持字重调节,值为false,表示不支持字重调节。 | 411 412## OnDidChangeCallback<sup>12+</sup> 413 414type OnDidChangeCallback = (rangeBefore: TextRange, rangeAfter: TextRange) => void 415 416文本变换后回调。 417 418**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 419 420**系统能力:** SystemCapability.ArkUI.ArkUI.Full 421 422**参数:** 423 424| 参数名 | 类型 | 必填 | 说明 | 425| -- | -- | -- | -- | 426| rangeBefore | [TextRange](#textrange12) | 是 | 文本变化前将要被替换的文本范围。 | 427| rangeAfter | [TextRange](#textrange12) | 是 | 文本变化后新增内容的文本范围。 | 428 429## StyledStringChangedListener<sup>12+</sup> 430 431属性字符串的文本内容变化监听器。 432 433**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 434 435**系统能力:** SystemCapability.ArkUI.ArkUI.Full 436 437| 名称 | 类型 | 必填 | 说明 | 438| -- | -- | -- | -- | 439| onWillChange | Callback<[StyledStringChangeValue](#styledstringchangevalue12), boolean> | 否 | 文本内容将要变化回调函数。 | 440| onDidChange | [OnDidChangeCallback](#ondidchangecallback12) | 否 | 文本内容完成变化回调函数。 | 441 442## StyledStringChangeValue<sup>12+</sup> 443 444属性字符串的文本变化信息。 445 446**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 447 448**系统能力:** SystemCapability.ArkUI.ArkUI.Full 449 450| 名称 | 类型 | 必填 | 说明 | 451| -- | -- | -- | -- | 452| range | TextRange | 是 | 即将被替换的属性字符串子串在原字符串中的范围。 | 453| replacementString | [StyledString](ts-universal-styled-string.md#styledstring) | 是 | 用于替换的属性字符串。 | 454| previewText | [StyledString](ts-universal-styled-string.md#styledstring) | 否 | 预览样式字符串。 | 455 456## TextBaseController<sup>12+</sup> 457 458文本选择控制器。 459 460**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 461 462**系统能力:** SystemCapability.ArkUI.ArkUI.Full 463 464### setSelection<sup>12+</sup> 465 466setSelection(selectionStart: number, selectionEnd: number, options?: SelectionOptions): void 467 468支持设置组件内的内容选中,选中部分背板高亮。 469 470selectionStart和selectionEnd均为-1时表示全选。 471 472未获焦时调用该接口不产生选中效果。 473 474从API version 12开始,在2in1设备中,无论options取何值,调用setSelection接口都不会弹出菜单,此外,如果组件中已经存在菜单,调用setSelection接口会关闭菜单。 475 476在非2in1设备中,options取值为MenuPolicy.DEFAULT时,遵循以下规则: 477 4781. 组件内有手柄菜单时,接口调用后不关闭菜单,并且调整菜单位置。 479 4802. 组件内有不带手柄的菜单时,接口调用后不关闭菜单,并且菜单位置不变。 481 4823. 组件内无菜单时,接口调用后也无菜单显示。 483 484**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 485 486**系统能力:** SystemCapability.ArkUI.ArkUI.Full 487 488**参数:** 489 490| 参数名 | 类型 | 必填 | 说明 | 491| -------------- | ------ | ---- | ------- | 492| selectionStart | number | 是 | 选中开始位置。<br/>取值小于0时,按0处理。 | 493| selectionEnd | number | 是 | 选中结束位置。<br/>取值大于文本长度时,按当前文本长度处理。 | 494| options | [SelectionOptions](ts-types.md#selectionoptions12对象说明) | 否 | 选择项配置。 | 495 496### closeSelectionMenu<sup>12+</sup> 497 498closeSelectionMenu(): void 499 500关闭自定义选择菜单或系统默认选择菜单。 501 502**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 503 504**系统能力:** SystemCapability.ArkUI.ArkUI.Full 505 506### getLayoutManager<sup>12+</sup> 507 508getLayoutManager(): LayoutManager 509 510获取布局管理器对象。 511 512**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 513 514**系统能力:** SystemCapability.ArkUI.ArkUI.Full 515 516**返回值:** 517 518| 类型 | 说明 | 519| ---------------------------------------- | ------- | 520| [LayoutManager](ts-text-common.md#layoutmanager12) | 布局管理器对象。 | 521 522## TextEditControllerEx<sup>12+</sup> 523 524文本扩展编辑控制器。 525 526继承自[TextBaseController](#textbasecontroller12)。 527 528**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 529 530**系统能力:** SystemCapability.ArkUI.ArkUI.Full 531 532### isEditing<sup>12+</sup> 533 534isEditing(): boolean 535 536获取当前富文本的编辑状态。 537 538**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 539 540**系统能力:** SystemCapability.ArkUI.ArkUI.Full 541 542**返回值:** 543 544| 类型 | 说明 | 545| ------- | ----------------------------- | 546| boolean | true为编辑态,false为非编辑态。 | 547 548### stopEditing<sup>12+</sup> 549 550stopEditing(): void 551 552退出编辑态。 553 554**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 555 556**系统能力:** SystemCapability.ArkUI.ArkUI.Full 557 558### getCaretOffset<sup>12+</sup> 559 560getCaretOffset(): number 561 562返回当前光标所在位置。 563 564**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 565 566**系统能力:** SystemCapability.ArkUI.ArkUI.Full 567 568**返回值:** 569 570| 类型 | 说明 | 571| ------ | --------- | 572| number | 当前光标所在位置。 | 573 574### setCaretOffset<sup>12+</sup> 575 576setCaretOffset(offset: number): boolean 577 578设置光标位置。 579 580**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 581 582**系统能力:** SystemCapability.ArkUI.ArkUI.Full 583 584**参数:** 585 586| 参数名 | 类型 | 必填 | 说明 | 587| ------ | ------ | ---- | -------------------- | 588| offset | number | 是 | 光标偏移位置。超出所有内容范围时,设置失败。 | 589 590**返回值:** 591 592| 类型 | 说明 | 593| ------- | --------- | 594| boolean | 光标是否设置成功。 | 595 596### getPreviewText<sup>12+</sup> 597 598getPreviewText?(): PreviewText 599 600获取预上屏信息。 601 602**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 603 604**系统能力:** SystemCapability.ArkUI.ArkUI.Full 605 606**返回值:** 607 608| 类型 | 说明 | 609| ---------------------------------------- | ------- | 610| [PreviewText](#previewtext12) | 预上屏信息。 |. 611 612## StyledStringController<sup>12+</sup> 613 614定义StyledString控制器。 615 616**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 617 618**系统能力:** SystemCapability.ArkUI.ArkUI.Full 619 620### setStyledString<sup>12+</sup> 621 622setStyledString(styledString: StyledString): void 623 624设置富文本组件显示的属性字符串。 625 626**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 627 628**系统能力:** SystemCapability.ArkUI.ArkUI.Full 629 630**参数:** 631 632| 参数名 | 类型 | 必填 | 说明 | 633| ----- | ------ | ---- | ------------------- | 634| styledString | [StyledString](ts-universal-styled-string.md#styledstring) | 是 | 属性字符串。<br/>**说明:** <br/>StyledString的子类[MutableStyledString](ts-universal-styled-string.md#mutablestyledstring)也可以作为入参值。 | 635 636### getStyledString<sup>12+</sup> 637 638getStyledString(): MutableStyledString 639 640获取富文本组件显示的属性字符串。 641 642**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 643 644**系统能力:** SystemCapability.ArkUI.ArkUI.Full 645 646**返回值:** 647 648| 类型 | 说明 | 649| ------- | ----------------------------- | 650| [MutableStyledString](ts-universal-styled-string.md#mutablestyledstring) | 富文本组件显示的属性字符串。 | 651 652## DecorationStyleResult<sup>12+</sup> 653 654后端返回的文本装饰线样式信息。 655 656**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 657 658**系统能力:** SystemCapability.ArkUI.ArkUI.Full 659 660| 名称 | 类型 | 必填 | 说明 | 661| ------- | --------------------------------- | ---- | --------------------------------- | 662| type | [TextDecorationType](ts-appendix-enums.md#textdecorationtype) | 是 | 装饰线类型。 | 663| color | [ResourceColor](ts-types.md#resourcecolor) | 是 | 装饰线颜色。 | 664| style | [TextDecorationStyle](ts-appendix-enums.md#textdecorationstyle12) | 否 | 装饰线样式。 | 665 666## LineMetrics<sup>12+</sup> 667 668type LineMetrics = LineMetrics 669 670用于描述文本布局中单行文字的度量信息。 671 672**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 673 674**系统能力:** SystemCapability.ArkUI.ArkUI.Full 675 676| 类型 | 说明 | 677| --------------------------------- | --------------------------------- | 678| [LineMetrics](../../apis-arkgraphics2d/js-apis-graphics-text.md#linemetrics) | 用于描述文本布局中单行文字的度量信息。 | 679 680## Affinity<sup>12+</sup> 681 682type Affinity = Affinity 683 684位置亲和度枚举。 685 686**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 687 688**系统能力:** SystemCapability.ArkUI.ArkUI.Full 689 690| 类型 | 说明 | 691| --------------------------------- | --------------------------------- | 692| [Affinity](../../apis-arkgraphics2d/js-apis-graphics-text.md#affinity) | 位置亲和度枚举。 | 693 694## TextBox<sup>14+</sup> 695 696type TextBox = TextBox 697 698文本矩形区域。 699 700**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 701 702**系统能力:** SystemCapability.ArkUI.ArkUI.Full 703 704| 类型 | 说明 | 705| --------------------------------- | --------------------------------- | 706| [TextBox](../../apis-arkgraphics2d/js-apis-graphics-text.md#textbox) | 文本矩形区域。 | 707 708## RectHeightStyle<sup>14+</sup> 709 710type RectHeightStyle = RectHeightStyle 711 712矩形区域高度规格枚举。 713 714**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 715 716**系统能力:** SystemCapability.ArkUI.ArkUI.Full 717 718| 类型 | 说明 | 719| --------------------------------- | --------------------------------- | 720| [RectHeightStyle](../../apis-arkgraphics2d/js-apis-graphics-text.md#rectheightstyle) | 矩形区域高度规格枚举。 | 721 722## RectWidthStyle<sup>14+</sup> 723 724type RectWidthStyle = RectWidthStyle 725 726矩形区域宽度规格枚举。 727 728**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 729 730**系统能力:** SystemCapability.ArkUI.ArkUI.Full 731 732| 类型 | 说明 | 733| --------------------------------- | --------------------------------- | 734| [RectWidthStyle](../../apis-arkgraphics2d/js-apis-graphics-text.md#rectwidthstyle) | 矩形区域宽度规格枚举。 | 735 736## TextChangeOptions<sup>15+</sup>对象说明 737 738变化前的文本信息,以及变化后的选区范围。 739 740**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 741 742**系统能力:** SystemCapability.ArkUI.ArkUI.Full 743 744| 名称 | 类型 | 必填 | 说明 | 745| ------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 746| rangeBefore | [TextRange](#textrange12) | 是 | 变化前的选区范围。 | 747| rangeAfter | [TextRange](#textrange12) | 是 | 变化后的选区范围。 | 748| oldContent | string | 是 | 变化前的文本内容。 | 749| oldPreviewText | [PreviewText](#previewtext12) | 是 | 变化前的预上屏信息。 | 750 751## EditableTextChangeValue<sup>15+</sup> 752 753文本变化的详细信息,包括预上屏。 754 755**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 756 757**系统能力:** SystemCapability.ArkUI.ArkUI.Full 758 759| 名称 | 类型 | 必填 | 说明 | 760| ------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 761| content | string | 是 | 当前的文本内容。 | 762| previewText | [PreviewText](#previewtext12) | 否 | 预上屏的内容信息。 | 763| options | [TextChangeOptions](#textchangeoptions15对象说明) | 否 | 变化的文本内容信息。 |