1# 安全控件通用属性 2 3<!--Kit: ArkUI--> 4<!--Subsystem: Security--> 5<!--Owner: @harylee--> 6<!--Designer: @linshuqing; @hehehe-li--> 7<!--Tester: @leiyuqian--> 8<!--Adviser: @zengyawen--> 9 10安全控件的基础属性,用于设置安全控件通用的属性。 11 12> **说明:** 13> 14> 该组件从API version 10开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 15 16## iconSize 17 18iconSize(value: Dimension): T 19 20设置安全控件图标的尺寸。 21 22**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 23 24**系统能力:** SystemCapability.ArkUI.ArkUI.Full 25 26**参数:** 27 28| 参数名 | 类型 | 必填 | 说明 | 29|------------|------|-------|---------| 30| value | [Dimension](ts-types.md#dimension10) | 是 |安全控件上图标的尺寸。<br/>默认值:16vp。<br/>不支持设置百分比字符串。| 31 32**返回值:** 33 34| 类型 | 说明 | 35| -------- | -------- | 36| T | 返回安全控件的属性。 | 37 38## layoutDirection 39 40layoutDirection(value: SecurityComponentLayoutDirection): T 41 42设置安全控件图标和文字分布的方向。 43 44**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 45 46**系统能力:** SystemCapability.ArkUI.ArkUI.Full 47 48**参数:** 49 50| 参数名 | 类型 | 必填 | 说明 | 51|------------|------|-------|---------| 52| value | [SecurityComponentLayoutDirection](#securitycomponentlayoutdirection枚举说明) |是 | 安全控件上图标和文字分布的方向。<br/>默认值:SecurityComponentLayoutDirection.HORIZONTAL。| 53 54**返回值:** 55 56| 类型 | 说明 | 57| -------- | -------- | 58| T | 返回安全控件的属性。 | 59 60## position 61 62position(value: Position): T 63 64设置绝对定位,设置安全控件的左上角相对于父容器左上角的偏移位置。 65 66**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 67 68**系统能力:** SystemCapability.ArkUI.ArkUI.Full 69 70**参数:** 71 72| 参数名 | 类型 | 必填 | 说明 | 73|------------|------|-------|---------| 74| value | [Position](ts-types.md#position) |是 |安全控件的左上角相对于父容器左上角的偏移位置。<br/>默认值:<br/>{<br/>x: 0,<br/>y: 0<br/>}。| 75 76**返回值:** 77 78| 类型 | 说明 | 79| -------- | -------- | 80| T | 返回安全控件的属性。 | 81 82## markAnchor 83 84markAnchor(value: Position): T 85 86设置安全控件在位置定位时的锚点,以控件左上角作为基准点进行偏移。 87 88**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 89 90**系统能力:** SystemCapability.ArkUI.ArkUI.Full 91 92**参数:** 93 94| 参数名 | 类型 | 必填 | 说明 | 95|------------|------|-------|---------| 96| value | [Position](ts-types.md#position) |是 |安全控件在位置定位时的锚点,以控件左上角作为基准点进行偏移。通常配合position和offset属性使用,单独使用时,效果类似offset。<br/>默认值:<br/>{<br/>x: 0,<br/>y: 0<br/>}。| 97 98**返回值:** 99 100| 类型 | 说明 | 101| -------- | -------- | 102| T | 返回安全控件的属性。 | 103 104## offset 105 106offset(value: Position | Edges | LocalizedEdges): T 107 108设置安全控件相对于自身布局位置的坐标偏移。 109 110**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 111 112**系统能力:** SystemCapability.ArkUI.ArkUI.Full 113 114**参数:** 115 116| 参数名 | 类型 | 必填 | 说明 | 117|------------|------|-------|---------| 118| value | [Position](ts-types.md#position) \| [Edges<sup>12+</sup>](ts-types.md#edges12) \| [LocalizedEdges<sup>12+</sup>](ts-types.md#localizededges12) |是 |安全控件相对于自身布局位置的坐标偏移。设置此属性不会影响父容器的布局,仅在绘制过程中调整位置。<br/>默认值:<br/>{<br/>x: 0,<br/>y: 0<br/>}。| 119 120**返回值:** 121 122| 类型 | 说明 | 123| -------- | -------- | 124| T | 返回安全控件的属性。 | 125 126## fontSize 127 128fontSize(value: Dimension): T 129 130设置安全控件文字的尺寸。 131 132**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 133 134**系统能力:** SystemCapability.ArkUI.ArkUI.Full 135 136**参数:** 137 138| 参数名 | 类型 | 必填 | 说明 | 139|------------|------|-------|---------| 140| value | [Dimension](ts-types.md#dimension10) |是 |安全控件上文字的尺寸。<br/>默认值:16fp。<br/>不支持设置百分比字符串。| 141 142**返回值:** 143 144| 类型 | 说明 | 145| -------- | -------- | 146| T | 返回安全控件的属性。 | 147 148## fontStyle 149 150fontStyle(value: FontStyle): T 151 152设置安全控件文字的样式。 153 154**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 155 156**系统能力:** SystemCapability.ArkUI.ArkUI.Full 157 158**参数:** 159 160| 参数名 | 类型 | 必填 | 说明 | 161|------------|------|-------|---------| 162| value | [FontStyle](ts-appendix-enums.md#fontstyle) |是 |安全控件上文字的样式。<br/>默认值:FontStyle.Normal。| 163 164**返回值:** 165 166| 类型 | 说明 | 167| -------- | -------- | 168| T | 返回安全控件的属性。 | 169 170## fontWeight 171 172fontWeight(value: number | FontWeight | string | Resource): T 173 174设置安全控件文字粗细。 175 176**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 177 178**系统能力:** SystemCapability.ArkUI.ArkUI.Full 179 180**参数:** 181 182| 参数名 | 类型 | 必填 | 说明 | 183|------------|------|-------|---------| 184| value | number \| [FontWeight](ts-appendix-enums.md#fontweight) \| string \| [Resource](ts-types.md#resource)<sup>20+</sup> |是 |安全控件上文字粗细。<br/>number类型取值[100, 900],取值间隔为100,取值越大,字体越粗。<br/>string类型支持使用数字字符串(如'400'),以及FontWeight中的枚举值对应的字符串(如'bold'、'bolder'、'lighter'、'regular'、'medium')。<br/>从API version 20开始,支持Resource类型。Resource类型仅支持'integer'和'string',当类型为'integer'时,取值参考前述number类型;当类型为'string'时,取值参考前述string类型。<br/>如果控件未设置fontWeight,文字粗细将默认设置为FontWeight.Medium;如果value入参为非法值,文字粗细将被设置为FontWeight.Normal。| 185 186**返回值:** 187 188| 类型 | 说明 | 189| -------- | -------- | 190| T | 返回安全控件的属性。 | 191 192## fontFamily 193 194fontFamily(value: string | Resource): T 195 196设置安全控件文字的字体。 197 198**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 199 200**系统能力:** SystemCapability.ArkUI.ArkUI.Full 201 202**参数:** 203 204| 参数名 | 类型 | 必填 | 说明 | 205|------------|------|-------|---------| 206| value | string \| [Resource](ts-types.md#resource) |是 |安全控件上文字的字体。<br/>默认字体:'HarmonyOS Sans'。| 207 208**返回值:** 209 210| 类型 | 说明 | 211| -------- | -------- | 212| T | 返回安全控件的属性。 | 213 214## fontColor 215 216fontColor(value: ResourceColor): T 217 218设置安全控件文字的颜色。 219 220**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 221 222**系统能力:** SystemCapability.ArkUI.ArkUI.Full 223 224**参数:** 225 226| 参数名 | 类型 | 必填 | 说明 | 227|------------|------|-------|---------| 228| value | [ResourceColor](ts-types.md#resourcecolor) |是 |安全控件上文字的颜色。<br/>默认值:$r('sys.color.font_on_primary')。| 229 230**返回值:** 231 232| 类型 | 说明 | 233| -------- | -------- | 234| T | 返回安全控件的属性。 | 235 236## iconColor 237 238iconColor(value: ResourceColor): T 239 240设置安全控件图标的颜色。 241 242**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 243 244**系统能力:** SystemCapability.ArkUI.ArkUI.Full 245 246**参数:** 247 248| 参数名 | 类型 | 必填 | 说明 | 249|------------|------|-------|---------| 250| value | [ResourceColor](ts-types.md#resourcecolor) |是 |安全控件上图标的颜色。<br/>默认值:$r('sys.color.icon_on_primary')。| 251 252**返回值:** 253 254| 类型 | 说明 | 255| -------- | -------- | 256| T | 返回安全控件的属性。 | 257 258## backgroundColor 259 260backgroundColor(value: ResourceColor): T 261 262设置安全控件的背景颜色。 263 264**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 265 266**系统能力:** SystemCapability.ArkUI.ArkUI.Full 267 268**参数:** 269 270| 参数名 | 类型 | 必填 | 说明 | 271|------------|------|-------|---------| 272| value | [ResourceColor](ts-types.md#resourcecolor) |是 |安全控件的背景颜色。安全控件按钮背景色高八位的α值低于0x1a(例如0x1800ff00)时,安全控件按钮背景色高八位的α值会被系统强制调整为0xff。<br/>默认值:$r('sys.color.icon_emphasize')。| 273 274**返回值:** 275 276| 类型 | 说明 | 277| -------- | -------- | 278| T | 返回安全控件的属性。 | 279 280## borderStyle 281 282borderStyle(value: BorderStyle): T 283 284设置安全控件的边框的样式。 285 286**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 287 288**系统能力:** SystemCapability.ArkUI.ArkUI.Full 289 290**参数:** 291 292| 参数名 | 类型 | 必填 | 说明 | 293|------------|------|-------|---------| 294| value | [BorderStyle](ts-appendix-enums.md#borderstyle) |是 |安全控件的边框的样式。<br/>默认不设置边框样式。| 295 296**返回值:** 297 298| 类型 | 说明 | 299| -------- | -------- | 300| T | 返回安全控件的属性。 | 301 302## borderWidth 303 304borderWidth(value: Dimension): T 305 306设置安全控件的边框宽度。 307 308**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 309 310**系统能力:** SystemCapability.ArkUI.ArkUI.Full 311 312**参数:** 313 314| 参数名 | 类型 | 必填 | 说明 | 315|------------|------|-------|---------| 316| value | [Dimension](ts-types.md#dimension10) |是 |安全控件的边框宽度。<br/>默认不设置边框宽度。| 317 318**返回值:** 319 320| 类型 | 说明 | 321| -------- | -------- | 322| T | 返回安全控件的属性。 | 323 324## borderColor 325 326borderColor(value: ResourceColor): T 327 328设置安全控件的边框颜色。 329 330**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 331 332**系统能力:** SystemCapability.ArkUI.ArkUI.Full 333 334**参数:** 335 336| 参数名 | 类型 | 必填 | 说明 | 337|------------|------|-------|---------| 338| value | [ResourceColor](ts-types.md#resourcecolor) |是 |安全控件的边框颜色。<br/>默认不设置边框颜色。| 339 340**返回值:** 341 342| 类型 | 说明 | 343| -------- | -------- | 344| T | 返回安全控件的属性。 | 345 346## borderRadius 347 348borderRadius(value: Dimension): T 349 350设置安全控件的边框圆角半径。 351 352**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 353 354**系统能力:** SystemCapability.ArkUI.ArkUI.Full 355 356**参数:** 357 358| 参数名 | 类型 | 必填 | 说明 | 359|------------|------|-------|---------| 360| value | [Dimension](ts-types.md#dimension10) |是 |安全控件的边框圆角半径。| 361 362**返回值:** 363 364| 类型 | 说明 | 365| -------- | -------- | 366| T | 返回安全控件的属性。 | 367 368## borderRadius<sup>15+</sup> 369 370borderRadius(radius: Dimension | BorderRadiuses): T 371 372设置安全控件的边框圆角半径,支持分别设置四个圆角的半径。 373 374**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 375 376**系统能力:** SystemCapability.ArkUI.ArkUI.Full 377 378**参数:** 379 380| 参数名 | 类型 | 必填 | 说明 | 381|------------|------|-------|---------| 382| radius | [Dimension](ts-types.md#dimension10) \| [BorderRadiuses](ts-types.md#borderradiuses9) |是 |安全控件的边框圆角半径。| 383 384**返回值:** 385 386| 类型 | 说明 | 387| -------- | -------- | 388| T | 返回安全控件的属性。 | 389 390## padding 391 392padding(value: Padding | Dimension): T 393 394设置安全控件的内边距。 395 396**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 397 398**系统能力:** SystemCapability.ArkUI.ArkUI.Full 399 400**参数:** 401 402| 参数名 | 类型 | 必填 | 说明 | 403|------------|------|-------|---------| 404| value | [Padding](ts-types.md#padding) \| [Dimension](ts-types.md#dimension10) |是 |安全控件的内边距。<br/>默认值:上下8vp,左右16vp。| 405 406**返回值:** 407 408| 类型 | 说明 | 409| -------- | -------- | 410| T | 返回安全控件的属性。 | 411 412## align<sup>15+</sup> 413 414align(alignType: Alignment): T 415 416设置安全控件图标文本的对齐方式。 417 418**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 419 420**系统能力:** SystemCapability.ArkUI.ArkUI.Full 421 422**参数:** 423 424| 参数名 | 类型 | 必填 | 说明 | 425|------------|------|-------|---------| 426| alignType | [Alignment](ts-appendix-enums.md#alignment) |是 |安全控件图标文本的对齐方式。图标文本作为整体在控件背托范围内进行对齐,UX显示受[padding](ts-securitycomponent-attributes.md#padding)影响,在padding生效的基础上进行指定方式对齐。<br/>默认值:Alignment.Center。| 427 428**返回值:** 429 430| 类型 | 说明 | 431| -------- | -------- | 432| T | 返回安全控件的属性。 | 433 434## textIconSpace 435 436textIconSpace(value: Dimension): T 437 438设置安全控件中图标和文字的间距。 439 440**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 441 442**系统能力:** SystemCapability.ArkUI.ArkUI.Full 443 444**参数:** 445 446| 参数名 | 类型 | 必填 | 说明 | 447|------------|------|-------|---------| 448| value | [Dimension](ts-types.md#dimension10) |是 |安全控件中图标和文字的间距。不支持设置百分比字符串。从API 14开始,若设置值为负值,则使用默认值。<br/>默认值:4vp。| 449 450**返回值:** 451 452| 类型 | 说明 | 453| -------- | -------- | 454| T | 返回安全控件的属性。 | 455 456## width<sup>11+</sup> 457 458width(value: Length): T 459 460设置安全控件自身的宽度,缺省时将根据元素内容自适配宽度。 461 462**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 463 464**系统能力:** SystemCapability.ArkUI.ArkUI.Full 465 466**参数:** 467 468| 参数名 | 类型 | 必填 | 说明 | 469|------------|------|-------|---------| 470|value | [Length](ts-types.md#length) |是 |安全控件自身的宽度,缺省时将根据元素内容自适配宽度。| 471 472**返回值:** 473 474| 类型 | 说明 | 475| -------- | -------- | 476| T | 返回安全控件的属性。 | 477 478## height<sup>11+</sup> 479 480height(value: Length): T 481 482设置安全控件自身的高度,缺省时将根据元素内容自适配高度。 483 484**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 485 486**系统能力:** SystemCapability.ArkUI.ArkUI.Full 487 488**参数:** 489 490| 参数名 | 类型 | 必填 | 说明 | 491|------------|------|-------|---------| 492| value | [Length](ts-types.md#length) |是|安全控件自身的高度,缺省时将根据元素内容自适配高度。| 493 494**返回值:** 495 496| 类型 | 说明 | 497| -------- | -------- | 498| T | 返回安全控件的属性。 | 499 500## size<sup>11+</sup> 501 502size(value: SizeOptions): T 503 504设置宽高尺寸,缺省时将根据元素内容自适配高宽尺寸。 505 506**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 507 508**系统能力:** SystemCapability.ArkUI.ArkUI.Full 509 510**参数:** 511 512| 参数名 | 类型 | 必填 | 说明 | 513|------------|------|-------|---------| 514| value | [SizeOptions](ts-types.md#sizeoptions) |是 |宽高尺寸,缺省时将根据元素内容自适配高宽尺寸。| 515 516**返回值:** 517 518| 类型 | 说明 | 519| -------- | -------- | 520| T | 返回安全控件的属性。 | 521 522## constraintSize<sup>11+</sup> 523 524constraintSize(value: ConstraintSizeOptions): T 525 526设置约束尺寸,组件布局时限制尺寸范围。 527 528**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 529 530**系统能力:** SystemCapability.ArkUI.ArkUI.Full 531 532**参数:** 533 534| 参数名 | 类型 | 必填 | 说明 | 535|------------|------|-------|---------| 536| value | [ConstraintSizeOptions](ts-types.md#constraintsizeoptions) |是 |约束尺寸,组件布局时,进行尺寸范围限制。constraintSize的优先级高于Width和Height。取值结果参考[constraintSize取值对width/height影响](ts-universal-attributes-size.md#constraintsize)。<br>默认值:<br>{<br/>minWidth: 0,<br/>maxWidth: Infinity,<br/>minHeight: 0,<br/>maxHeight: Infinity<br/>}。| 537 538**返回值:** 539 540| 类型 | 说明 | 541| -------- | -------- | 542| T | 返回安全控件的属性。 | 543 544## alignRules<sup>15+</sup> 545 546alignRules(alignRule: AlignRuleOption): T 547 548指定设置在相对容器中子组件的对齐规则,仅当父容器为[RelativeContainer](ts-container-relativecontainer.md)时生效。 549 550**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 551 552**系统能力:** SystemCapability.ArkUI.ArkUI.Full 553 554**参数:** 555 556| 参数名 | 类型 | 必填 | 说明 | 557| ------ | ------------------------------------------- | ---- | ------------------------ | 558| alignRule | [AlignRuleOption](ts-universal-attributes-location.md#alignruleoption9对象说明) | 是 | 指定设置在相对容器中子组件的对齐规则。 | 559 560**返回值:** 561 562| 类型 | 说明 | 563| -------- | -------- | 564| T | 返回安全控件的属性。 | 565 566## alignRules<sup>15+</sup> 567 568alignRules(alignRule: LocalizedAlignRuleOptions): T 569 570指定设置在相对容器中子组件的对齐规则,仅当父容器为[RelativeContainer](ts-container-relativecontainer.md)时生效。该方法水平方向上以start和end分别替代上述[alignRules](#alignrules15)的left和right,以便在RTL模式下能镜像显示,建议使用该方法指定设置在相对容器中子组件的对齐规则。 571 572**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 573 574**系统能力:** SystemCapability.ArkUI.ArkUI.Full 575 576**参数:** 577 578| 参数名 | 类型 | 必填 | 说明 | 579| ------ | ------------------------------------------- | ---- | ------------------------ | 580| alignRule | [LocalizedAlignRuleOptions](ts-universal-attributes-location.md#localizedalignruleoptions12对象说明) | 是 | 指定设置在相对容器中子组件的对齐规则。 | 581 582**返回值:** 583 584| 类型 | 说明 | 585| -------- | -------- | 586| T | 返回安全控件的属性。 | 587 588## id<sup>15+</sup> 589 590id(description: string): T 591 592组件的唯一标识,唯一性由使用者保证。 593 594**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 595 596**系统能力:** SystemCapability.ArkUI.ArkUI.Full 597 598**参数:** 599 600| 参数名 | 类型 | 必填 | 说明 | 601| ------ | -------- | -----|---------------------- | 602| description | string | 是 | 组件的唯一标识,唯一性由使用者保证。<br>默认值:''。<br/> | 603 604**返回值:** 605 606| 类型 | 说明 | 607| -------- | -------- | 608| T | 返回安全控件的属性。 | 609 610## chainMode<sup>15+</sup> 611 612chainMode(direction: Axis, style: ChainStyle): T 613 614指定以该组件为链头所构成的链的参数,仅当父容器为[RelativeContainer](ts-container-relativecontainer.md)时生效。 615 616**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 617 618**系统能力:** SystemCapability.ArkUI.ArkUI.Full 619 620**参数:** 621 622| 参数名 | 类型 | 必填 | 说明 | 623| ------ | ------------------------------------------- | ---- | ------------------------ | 624| direction | [Axis](ts-appendix-enums.md#axis) | 是 | 链的方向。 | 625| style | [ChainStyle](ts-universal-attributes-location.md#chainstyle12) | 是 | 链的样式。 | 626 627**返回值:** 628 629| 类型 | 说明 | 630| -------- | -------- | 631| T | 返回安全控件的属性。 | 632 633## minFontScale<sup>18+</sup> 634 635minFontScale(scale: number | Resource): T 636 637设置文本最小的字体缩小倍数。 638 639**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 640 641**系统能力:** SystemCapability.ArkUI.ArkUI.Full 642 643**参数:** 644 645| 参数名 | 类型 | 必填 | 说明 | 646| ------ | --------------------------------------------- | ---- | --------------------------------------------- | 647| scale | number \| [Resource](ts-types.md#resource) | 是 | 文本最小的字体缩小倍数。<br/>取值范围:[0, 1]。<br/>**说明:** <br/>设置的值小于0时,按值为0处理,即缩小不受限制;设置的值大于1,按值为1处理,即缩小不生效;取值范围外为异常值,默认不生效。 | 648 649**返回值:** 650 651| 类型 | 说明 | 652| -------- | -------- | 653| T | 返回安全控件的属性。 | 654 655## maxFontScale<sup>18+</sup> 656 657maxFontScale(scale: number | Resource): T 658 659设置文本最大的字体放大倍数。 660 661**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 662 663**系统能力:** SystemCapability.ArkUI.ArkUI.Full 664 665**参数:** 666 667| 参数名 | 类型 | 必填 | 说明 | 668| ------ | --------------------------------------------- | ---- | --------------------------------------------- | 669| scale | number \| [Resource](ts-types.md#resource) | 是 | 文本最大的字体放大倍数。<br/>取值范围:[1, +∞)。<br/>**说明:** <br/>设置的值小于1时,按值为1处理,异常值默认不生效。 | 670 671**返回值:** 672 673| 类型 | 说明 | 674| -------- | -------- | 675| T | 返回安全控件的属性。 | 676 677## minFontSize<sup>18+</sup> 678 679minFontSize(minSize: number | string | Resource): T 680 681设置文本最小显示字号。 682- 配合[maxFontSize](#maxfontsize18)以及[maxLines](#maxlines18)或布局大小限制使用,可实现自适应字号,单独设置不生效。 683- minFontSize小于或等于0时,自适应字号不生效。 684- 自适应字号生效时,fontSize设置不生效。 685 686**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 687 688**系统能力:** SystemCapability.ArkUI.ArkUI.Full 689 690**参数:** 691 692| 参数名 | 类型 | 必填 | 说明 | 693| ------ | ------------------------------------------------------------ | ---- | ------------------ | 694| minSize | number \| string \| [Resource](ts-types.md#resource) | 是 | 文本最小显示字号。 | 695 696**返回值:** 697 698| 类型 | 说明 | 699| -------- | -------- | 700| T | 返回安全控件的属性。 | 701 702## maxFontSize<sup>18+</sup> 703 704maxFontSize(maxSize: number | string | Resource): T 705 706设置文本最大显示字号。 707- 配合[minFontSize](#minfontsize18)以及[maxLines](#maxlines18)或布局大小限制使用,可实现自适应字号,单独设置不生效。 708- 当自适应字号生效时,设置的fontSize将不生效。 709 710**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 711 712**系统能力:** SystemCapability.ArkUI.ArkUI.Full 713 714**参数:** 715 716| 参数名 | 类型 | 必填 | 说明 | 717| ------ | ------------------------------------------------------------ | ---- | ------------------ | 718| maxSize | number \| string \| [Resource](ts-types.md#resource) | 是 | 文本最大显示字号。 | 719 720**返回值:** 721 722| 类型 | 说明 | 723| -------- | -------- | 724| T | 返回安全控件的属性。 | 725 726## maxLines<sup>18+</sup> 727 728maxLines(line: number | Resource): T 729 730设置文本的最大行数。默认情况下,文本自动换行,指定此属性后,文本的最大显示行数不会超过指定值。 731 732**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 733 734**系统能力:** SystemCapability.ArkUI.ArkUI.Full 735 736**参数:** 737 738| 参数名 | 类型 | 必填 | 说明 | 739| ------ | ------ | ---- | ---------------- | 740| line | number \| [Resource](ts-types.md#resource)<sup>20+</sup> | 是 | 文本的最大行数。<br/>number类型入参的取值范围:[1, +∞)。从API version 20开始,支持Resource类型。Resource类型仅支持'integer',取值范围为[1, +∞)。<br/>**说明:** <br/>设置的值小于1时,按默认值100000处理。 | 741 742**返回值:** 743 744| 类型 | 说明 | 745| -------- | -------- | 746| T | 返回安全控件的属性。 | 747 748## heightAdaptivePolicy<sup>18+</sup> 749 750heightAdaptivePolicy(policy: TextHeightAdaptivePolicy): T 751 752设置文本自适应高度的方式。 753 754通过文本自适应高度实现文本大小自适应。 755 756安全控件文本以[maxFontSize](#maxfontsize18)的值进行布局,如果可以完整显示文本,则无需进行自适应调节,该接口设置不生效,否则按指定文本自适应高度的方式进行调节,具体自适应调节规格如下: 757 758当设置为TextHeightAdaptivePolicy.MAX_LINES_FIRST时,优先使用[maxLines](#maxlines18)属性来调整文本高度。如果使用maxLines属性的布局大小超过了布局约束,则尝试在[minFontSize](#minfontsize18)和[maxFontSize](#maxfontsize18)的范围内缩小字体以显示更多文本,如果此时仍不能完整显示文本信息,安全控件会自适应调整高度以使得文本完整显示。 759 760当设置为TextHeightAdaptivePolicy.MIN_FONT_SIZE_FIRST时,优先使用[minFontSize](#minfontsize18)属性来调整文本高度。如果使用minFontSize属性可以将文本布局在一行中,则尝试在minFontSize和[maxFontSize](#maxfontsize18)的范围内增大字体并使用最大可能的字体大小;如果使用minFontSize属性无法将文本布局在一行中,则尝试使用[maxLines](#maxlines18)属性进行布局,如果此时仍不能完整显示文本信息,安全控件会自适应调整高度以使得文本完整显示。 761 762当设置为TextHeightAdaptivePolicy.LAYOUT_CONSTRAINT_FIRST时,优先使用布局约束来调整文本高度。如果布局大小超过布局约束,则尝试在[minFontSize](#minfontsize18)和[maxFontSize](#maxfontsize18)的范围内缩小字体以满足布局约束。如果将字体大小缩小到minFontSize后,布局大小仍然超过布局约束,则删除超过布局约束的行;如果设置了[maxLines](#maxlines18)属性,布局后行数不超过maxlines值(可能存在横向截断);如果未设置maxlines属性值,布局后的行数不限制。 763 764安全控件文本未完全显示时,点击不授权。 765 766具体效果请见[示例](#示例3)。 767 768**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 769 770**系统能力:** SystemCapability.ArkUI.ArkUI.Full 771 772**参数:** 773 774| 参数名 | 类型 | 必填 | 说明 | 775| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 776| policy | [TextHeightAdaptivePolicy](ts-appendix-enums.md#textheightadaptivepolicy10) | 是 | 文本自适应高度的方式。<br/>默认值:TextHeightAdaptivePolicy.MAX_LINES_FIRST。 | 777 778**返回值:** 779 780| 类型 | 说明 | 781| -------- | -------- | 782| T | 返回安全控件的属性。 | 783 784## enabled<sup>18+</sup> 785 786enabled(respond: boolean): T 787 788设置安全控件是否可交互。 789 790**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 791 792**系统能力:** SystemCapability.ArkUI.ArkUI.Full 793 794**参数:** 795 796| 参数名 | 类型 | 必填 | 说明 | 797| ------ | ------- | ---- | ------------------------------------------------------------ | 798| respond | boolean | 是 | 值为true表示组件可交互,响应点击等操作。<br/>值为false表示组件不可交互,不响应点击等操作。<br/>默认值:true。 | 799 800**返回值:** 801 802| 类型 | 说明 | 803| -------- | -------- | 804| T | 返回安全控件的属性。 | 805 806 807 808## SecurityComponentLayoutDirection枚举说明 809 810安全控件上图标和文字的排列方向。 811 812**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 813 814**系统能力:** SystemCapability.ArkUI.ArkUI.Full 815 816| 名称 | 值 | 说明 | 817| -------- | -------- | -------- | 818| HORIZONTAL | 0 | 安全控件上图标和文字分布的方向为水平排列。 | 819| VERTICAL | 1 | 安全控件上图标和文字分布的方向为垂直排列。 | 820 821## ButtonType枚举说明 822 823按钮类型。 824 825不同的按钮类型将影响属性[borderRadius(边框圆角半径)](ts-securitycomponent-attributes.md#borderradius)的设置效果。影响如下: 826 827- 当按钮类型为Capsule时,borderRadius设置不生效,按钮圆角半径始终为宽、高中较小值的一半。 828- 当按钮类型为Circle时,borderRadius设置不生效: 829 - 若同时设置了宽和高,按钮圆角半径为宽高中较小值的一半; 830 - 若只设置宽、高中的一个,按钮圆角半径为所设宽或所设高值的一半; 831 - 若未设置宽高或borderRadius的值为负数,按钮圆角半径将根据具体布局确定。 832- 当按钮类型为Normal时,按钮圆角半径可通过borderRadius设置,圆角大小受组件尺寸限制,最小值为0,最大值为组件宽高中较小值的一半。 833- 当按钮类型为ROUNDED_RECTANGLE时,若不设置borderRadius,圆角矩形按钮的圆角半径大小保持默认值20vp不变,不随按钮高度变化而变化。 834 835**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 836 837**系统能力:** SystemCapability.ArkUI.ArkUI.Full 838 839| 名称 | 值 | 说明 | 840| ------- | -------- | ------------------ | 841| Normal | 0 | 普通按钮(默认不带圆角)。 | 842| Capsule | 1 | 胶囊型按钮(圆角半径默认为高度的一半)。 | 843| Circle | 2 | 圆形按钮。 | 844| ROUNDED_RECTANGLE<sup>16+</sup> | 8 | 圆角矩形按钮(默认值:圆角半径大小20vp)。 | 845 846## 示例 847 848> **说明:** 849> 为避免控件样式不合法导致授权失败,请开发者先了解安全控件样式的[约束与限制](../../../security/AccessToken/security-component-overview.md#约束与限制)。 850 851### 示例1 852 853设置SecurityComponent的基础属性,生成一个保存控件。 854 855```ts 856@Entry 857@Component 858struct Index { 859 build() { 860 Row() { 861 Column({ space: 5 }) { 862 // 生成一个保存控件,并设置它的SecurityComponent属性。 863 SaveButton() 864 .fontSize(35) 865 .fontColor(Color.White) 866 .iconSize(30) 867 .layoutDirection(SecurityComponentLayoutDirection.HORIZONTAL) 868 .borderWidth(1) 869 .borderStyle(BorderStyle.Dashed) 870 .borderColor(Color.Blue) 871 .borderRadius(20) 872 .fontWeight(100) 873 .iconColor(Color.White) 874 .padding({ 875 left: 50, 876 top: 50, 877 bottom: 50, 878 right: 50 879 }) 880 .textIconSpace(20) 881 .backgroundColor(0x3282f6) 882 SaveButton().size({ width: 200, height: 100 }) 883 SaveButton() 884 .size({ width: 200, height: 100 }) 885 .align(Alignment.Start) 886 SaveButton({ icon: SaveIconStyle.FULL_FILLED, text: SaveDescription.DOWNLOAD, buttonType: ButtonType.Normal }) 887 .size({ width: 150, height: 80 }) 888 .borderRadius({ 889 topLeft: 20, 890 topRight: 25, 891 bottomRight: 30, 892 bottomLeft: 35 893 }) 894 SaveButton().constraintSize({ maxWidth: 60 }) 895 }.width('100%') 896 }.height('100%') 897 } 898} 899``` 900 901 902 903### 示例2 904 905以容器和容器内组件作为锚点进行布局。 906 907```ts 908@Entry 909@Component 910struct Index { 911 build() { 912 Row() { 913 RelativeContainer() { 914 SaveButton({ icon: SaveIconStyle.FULL_FILLED, text: SaveDescription.DOWNLOAD, buttonType: ButtonType.Normal }) 915 .width(100) 916 .height(100) 917 .backgroundColor('#A3CF62') 918 .alignRules({ 919 top: { anchor: '__container__', align: VerticalAlign.Top }, 920 left: { anchor: '__container__', align: HorizontalAlign.Start } 921 }) 922 .id('row1') 923 924 SaveButton({ icon: SaveIconStyle.FULL_FILLED, text: SaveDescription.DOWNLOAD, buttonType: ButtonType.Normal }) 925 .width(100) 926 .height(100) 927 .backgroundColor('#00AE9D') 928 .alignRules({ 929 top: { anchor: '__container__', align: VerticalAlign.Top }, 930 right: { anchor: '__container__', align: HorizontalAlign.End } 931 }) 932 .id('row2') 933 934 SaveButton({ icon: SaveIconStyle.FULL_FILLED, text: SaveDescription.DOWNLOAD, buttonType: ButtonType.Normal }) 935 .height(100) 936 .backgroundColor('#0A59F7') 937 .alignRules({ 938 top: { anchor: 'row1', align: VerticalAlign.Bottom }, 939 left: { anchor: 'row1', align: HorizontalAlign.End }, 940 right: { anchor: 'row2', align: HorizontalAlign.Start } 941 }) 942 .id('row3') 943 944 SaveButton({ icon: SaveIconStyle.FULL_FILLED, text: SaveDescription.DOWNLOAD, buttonType: ButtonType.Normal }) 945 .backgroundColor('#2CA9E0') 946 .alignRules({ 947 top: { anchor: 'row3', align: VerticalAlign.Bottom }, 948 bottom: { anchor: '__container__', align: VerticalAlign.Bottom }, 949 left: { anchor: '__container__', align: HorizontalAlign.Start }, 950 right: { anchor: 'row1', align: HorizontalAlign.End } 951 }) 952 .id('row4') 953 954 SaveButton({ icon: SaveIconStyle.FULL_FILLED, text: SaveDescription.DOWNLOAD, buttonType: ButtonType.Normal }) 955 .backgroundColor('#30C9F7') 956 .alignRules({ 957 top: { anchor: 'row3', align: VerticalAlign.Bottom }, 958 bottom: { anchor: '__container__', align: VerticalAlign.Bottom }, 959 left: { anchor: 'row2', align: HorizontalAlign.Start }, 960 right: { anchor: '__container__', align: HorizontalAlign.End } 961 }) 962 .id('row5') 963 } 964 .width(300).height(300) 965 .margin({ left: 50 }) 966 .border({ width: 2, color: '#6699FF' }) 967 } 968 .height('100%') 969 } 970} 971``` 972 973 974 975### 示例3 976 977```ts 978@Entry 979@Component 980struct Index { 981 build() { 982 Column() { 983 Scroll() { 984 Column({ space: 10 }) { 985 Column({ space: 10 }) { 986 Row() { 987 Text('FontSize = 20,图例:').fontSize(20) 988 Text('快速保存图片').fontSize(20).fontColor(Color.Blue) 989 }.width('100%') 990 991 Row() { 992 Text('FontSize = 10,图例:').fontSize(20) 993 Text('快速保存图片').fontSize(10).fontColor(Color.Blue) 994 }.width('100%') 995 }.width('100%') 996 997 Flex({ wrap: FlexWrap.Wrap }) { 998 Column() { 999 Row() { 1000 Text('heightAdaptivePolicy = MIN_FONT_SIZE_FIRST').fontSize(16).fontWeight(FontWeight.Bold) 1001 } 1002 }.height(40) 1003 1004 Column() { 1005 Column({ space: 10 }) { 1006 Row() { 1007 Text('无需自适应调节') 1008 }.width('90%') 1009 1010 //当前布局无需调整即可完整显示文本,文本无需自适应调节。 1011 SaveButton({ 1012 text: SaveDescription.QUICK_SAVE_TO_GALLERY, buttonType: ButtonType.Normal 1013 }) 1014 .maxFontSize(20) 1015 .minFontSize(10) 1016 .maxLines(6) 1017 .heightAdaptivePolicy(TextHeightAdaptivePolicy.MIN_FONT_SIZE_FIRST) 1018 .width(120) 1019 .height(20) 1020 .padding(0) 1021 .borderRadius(10) 1022 } 1023 }.width('50%').height(90).backgroundColor(0x10000000) 1024 1025 Column() { 1026 Column({ space: 10 }) { 1027 Row() { 1028 Text('优先减少字号') 1029 }.width('90%') 1030 1031 // 当前布局无法完整显示文字,优先缩小fontSize,缩小后可以一行显示。 1032 SaveButton({ 1033 text: SaveDescription.QUICK_SAVE_TO_GALLERY, buttonType: ButtonType.Normal 1034 }) 1035 .maxFontSize(20) 1036 .minFontSize(10) 1037 .maxLines(6) 1038 .heightAdaptivePolicy(TextHeightAdaptivePolicy.MIN_FONT_SIZE_FIRST) 1039 .width(60) 1040 .height(20) 1041 .padding(0) 1042 .borderRadius(10) 1043 } 1044 }.width('50%').height(90).backgroundColor(0x30000000) 1045 1046 Column() { 1047 Column({ space: 10 }) { 1048 Row() { 1049 Text('先减小字号,再换行') 1050 }.width('90%') 1051 1052 // 当前布局无法完整显示文字,优先缩小fontSize,缩小后仍然无法完整显示,尝试使用maxLines属性换行布局。 1053 // 由于高度不足以完整显示,自动调整高度使文本完整显示。 1054 SaveButton({ 1055 text: SaveDescription.QUICK_SAVE_TO_GALLERY, buttonType: ButtonType.Normal 1056 }) 1057 .maxFontSize(20) 1058 .minFontSize(10) 1059 .maxLines(6) 1060 .heightAdaptivePolicy(TextHeightAdaptivePolicy.MIN_FONT_SIZE_FIRST) 1061 .width(20) 1062 .height(20) 1063 .padding(0) 1064 .borderRadius(10) 1065 } 1066 }.width('50%').height(90).backgroundColor(0x30000000) 1067 1068 Column() { 1069 Column({ space: 10 }) { 1070 Row() { 1071 Text('减小字号+换行,文字被截断') 1072 }.width('90%') 1073 1074 // 当前布局无法完整显示文字,优先缩小fontSize,缩小后仍然无法完整显示,尝试使用maxLines属性换行布局。 1075 // 由于maxlines属性为3,只能显示三行,所以文字被截断。 1076 // 由于高度不足以完整显示,自动调整高度使文本完整显示。 1077 SaveButton({ 1078 text: SaveDescription.QUICK_SAVE_TO_GALLERY, buttonType: ButtonType.Normal 1079 }) 1080 .maxFontSize(20) 1081 .minFontSize(10) 1082 .maxLines(3) 1083 .heightAdaptivePolicy(TextHeightAdaptivePolicy.MIN_FONT_SIZE_FIRST) 1084 .width(10) 1085 .height(20) 1086 .padding(0) 1087 .borderRadius(10) 1088 } 1089 }.width('50%').height(90).backgroundColor(0x10000000) 1090 }.width('100%') 1091 1092 Flex({ wrap: FlexWrap.Wrap }) { 1093 Column() { 1094 Row() { 1095 Text('heightAdaptivePolicy = MAX_LINES_FIRST').fontSize(16).fontWeight(FontWeight.Bold) 1096 } 1097 }.height(40) 1098 1099 Column() { 1100 Column({ space: 10 }) { 1101 Row() { 1102 Text('无需自适应调节') 1103 }.width('90%') 1104 1105 //当前布局无需调整即可完整显示文本,文本无需自适应调节。 1106 SaveButton({ 1107 text: SaveDescription.QUICK_SAVE_TO_GALLERY, buttonType: ButtonType.Normal 1108 }) 1109 .maxFontSize(20) 1110 .minFontSize(10) 1111 .maxLines(6) 1112 .heightAdaptivePolicy(TextHeightAdaptivePolicy.MAX_LINES_FIRST) 1113 .width(120) 1114 .height(20) 1115 .padding(0) 1116 .borderRadius(10) 1117 } 1118 }.width('50%').height(90).backgroundColor(0x10000000) 1119 1120 Column() { 1121 Column({ space: 10 }) { 1122 Row() { 1123 Text('优先换行') 1124 }.width('90%') 1125 1126 // 当前布局无法完整显示文字,优先使用maxlines属性换行布局,换行后可以完整显示。 1127 // 由于高度不足以完整显示,自动调整高度使文本完整显示。 1128 SaveButton({ 1129 text: SaveDescription.QUICK_SAVE_TO_GALLERY, buttonType: ButtonType.Normal 1130 }) 1131 .maxFontSize(20) 1132 .minFontSize(10) 1133 .maxLines(6) 1134 .heightAdaptivePolicy(TextHeightAdaptivePolicy.MAX_LINES_FIRST) 1135 .width(60) 1136 .height(20) 1137 .padding(0) 1138 .borderRadius(10) 1139 } 1140 }.width('50%').height(90).backgroundColor(0x30000000) 1141 1142 Column() { 1143 Column({ space: 10 }) { 1144 Row() { 1145 Text('先换行,再减小字号') 1146 }.width('90%') 1147 1148 // 当前布局无法完整显示文字,优先使用maxlines属性换行布局,换行后仍然无法完整显示,缩小fontSize尝试布局,缩小字体后可以完整显示。 1149 // 由于高度不足以完整显示,自动调整高度使文本完整显示。 1150 SaveButton({ 1151 text: SaveDescription.QUICK_SAVE_TO_GALLERY, buttonType: ButtonType.Normal 1152 }) 1153 .maxFontSize(20) 1154 .minFontSize(10) 1155 .maxLines(3) 1156 .heightAdaptivePolicy(TextHeightAdaptivePolicy.MAX_LINES_FIRST) 1157 .width(20) 1158 .height(20) 1159 .padding(0) 1160 .borderRadius(10) 1161 } 1162 }.width('50%').height(90).backgroundColor(0x30000000) 1163 1164 Column() { 1165 Column({ space: 10 }) { 1166 Row() { 1167 Text('换行+减小字号,文字被截断') 1168 }.width('90%') 1169 1170 // 当前布局无法完整显示文字,优先使用maxlines属性换行布局,换行后仍然无法完整显示,缩小fontSize尝试布局。 1171 // 由于minFontSize属性为10,每行只能显示一个字,所以文字被截断。 1172 // 由于高度不足以完整显示,自动调整高度使文本完整显示。 1173 SaveButton({ 1174 text: SaveDescription.QUICK_SAVE_TO_GALLERY, buttonType: ButtonType.Normal 1175 }) 1176 .maxFontSize(20) 1177 .minFontSize(10) 1178 .maxLines(3) 1179 .heightAdaptivePolicy(TextHeightAdaptivePolicy.MAX_LINES_FIRST) 1180 .width(10) 1181 .height(20) 1182 .padding(0) 1183 .borderRadius(10) 1184 } 1185 }.width('50%').height(90).backgroundColor(0x10000000) 1186 }.width('100%') 1187 1188 Flex({ wrap: FlexWrap.Wrap }) { 1189 1190 Column() { 1191 Row() { 1192 Text('heightAdaptivePolicy = LAYOUT_CONSTRAINT_FIRST').fontSize(16).fontWeight(FontWeight.Bold) 1193 } 1194 }.height(40) 1195 1196 Column() { 1197 Column({ space: 10 }) { 1198 Row() { 1199 Text('无需自适应调节') 1200 }.width('90%') 1201 1202 //当前布局无需调整即可完整显示文本,文本无需自适应调节。 1203 SaveButton({ 1204 text: SaveDescription.QUICK_SAVE_TO_GALLERY, buttonType: ButtonType.Normal 1205 }) 1206 .maxFontSize(20) 1207 .minFontSize(10) 1208 .maxLines(6) 1209 .heightAdaptivePolicy(TextHeightAdaptivePolicy.LAYOUT_CONSTRAINT_FIRST) 1210 .width(120) 1211 .height(20) 1212 .padding(0) 1213 .borderRadius(10) 1214 } 1215 }.width('50%').height(90).backgroundColor(0x10000000) 1216 1217 Column() { 1218 Column({ space: 10 }) { 1219 Row() { 1220 Text('不改变布局约束,优先减小字号') 1221 }.width('90%') 1222 1223 // 当前布局无法完整显示文字,优先缩小fontSize,缩小后可以一行显示。 1224 SaveButton({ 1225 text: SaveDescription.QUICK_SAVE_TO_GALLERY, buttonType: ButtonType.Normal 1226 }) 1227 .maxFontSize(20) 1228 .minFontSize(10) 1229 .maxLines(6) 1230 .heightAdaptivePolicy(TextHeightAdaptivePolicy.LAYOUT_CONSTRAINT_FIRST) 1231 .width(60) 1232 .height(20) 1233 .padding(0) 1234 .borderRadius(10) 1235 } 1236 }.width('50%').height(90).backgroundColor(0x30000000) 1237 1238 Column() { 1239 Column({ space: 10 }) { 1240 Row() { 1241 Text('不改变布局约束,先减小字号再换行') 1242 }.width('90%') 1243 1244 // 当前布局无法完整显示文字,优先缩小fontSize,缩小后无法完整显示,使用maxlines属性进行换行布局。布局后可以完整显示。 1245 // LAYOUT_CONSTRAINT_FIRST模式下安全控件高度不支持自适应调整。 1246 SaveButton({ 1247 text: SaveDescription.QUICK_SAVE_TO_GALLERY, buttonType: ButtonType.Normal 1248 }) 1249 .maxFontSize(20) 1250 .minFontSize(10) 1251 .maxLines(6) 1252 .heightAdaptivePolicy(TextHeightAdaptivePolicy.LAYOUT_CONSTRAINT_FIRST) 1253 .width(20) 1254 .height(40) 1255 .padding(0) 1256 .borderRadius(10) 1257 } 1258 }.width('50%').height(90).backgroundColor(0x30000000) 1259 1260 Column() { 1261 Column({ space: 10 }) { 1262 Row() { 1263 Text(`Maxlines不够\n文字被截断`) 1264 }.width('90%') 1265 1266 // 当前布局无法完整显示文字,优先缩小fontSize,缩小后无法完整显示,但由于height只能显示一行,所以文字被截断。 1267 // LAYOUT_CONSTRAINT_FIRST模式下安全控件高度不支持自适应调整。 1268 SaveButton({ 1269 text: SaveDescription.QUICK_SAVE_TO_GALLERY, buttonType: ButtonType.Normal 1270 }) 1271 .maxFontSize(20) 1272 .minFontSize(10) 1273 .maxLines(2) 1274 .heightAdaptivePolicy(TextHeightAdaptivePolicy.LAYOUT_CONSTRAINT_FIRST) 1275 .width(20) 1276 .height(40) 1277 .padding(0) 1278 .borderRadius(10) 1279 } 1280 }.width('25%').height(90).backgroundColor(0x10000000) 1281 1282 Column() { 1283 Column({ space: 10 }) { 1284 Row() { 1285 Text(`高度不够\n文字被截断`) 1286 }.width('90%') 1287 1288 // 当前布局无法完整显示文字,优先缩小fontSize,缩小后无法完整显示,但由于height只能显示一行,所以文字被截断。 1289 // LAYOUT_CONSTRAINT_FIRST模式下安全控件高度不支持自适应调整。 1290 SaveButton({ 1291 text: SaveDescription.QUICK_SAVE_TO_GALLERY, buttonType: ButtonType.Normal 1292 }) 1293 .maxFontSize(20) 1294 .minFontSize(10) 1295 .maxLines(6) 1296 .heightAdaptivePolicy(TextHeightAdaptivePolicy.LAYOUT_CONSTRAINT_FIRST) 1297 .width(20) 1298 .height(20) 1299 .padding(0) 1300 .borderRadius(10) 1301 } 1302 }.width('25%').height(90).backgroundColor(0x20000000) 1303 }.width('100%') 1304 1305 }.width('100%') 1306 }.width('100%').margin({ top: 10, left: 10, right: 10 }) 1307 } 1308 } 1309} 1310``` 1311 1312