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