外描边设置

设置组件外描边样式。

说明:

从API Version 11开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。

outline

outline(value: OutlineOptions)

统一外描边样式设置接口。

卡片能力: 从API version 11开始,该接口支持在ArkTS卡片中使用。

系统能力: SystemCapability.ArkUI.ArkUI.Full

参数:

参数名 类型 必填 说明
value OutlineOptions 外描边样式。

outlineStyle

outlineStyle(value: OutlineStyle | EdgeOutlineStyles)

设置元素的外描边样式。

卡片能力: 从API version 11开始,该接口支持在ArkTS卡片中使用。

系统能力: SystemCapability.ArkUI.ArkUI.Full

参数:

参数名 类型 必填 说明
value OutlineStyle | EdgeOutlineStyles 设置元素的外描边样式。
默认值:OutlineStyle.SOLID

outlineWidth

outlineWidth(value: Dimension | EdgeOutlineWidths)

设置元素的外描边宽度。

卡片能力: 从API version 11开始,该接口支持在ArkTS卡片中使用。

系统能力: SystemCapability.ArkUI.ArkUI.Full

参数:

参数名 类型 必填 说明
value Dimension | EdgeOutlineWidths 设置元素的外描边宽度,不支持百分比。
默认值:0,外描边效果width为必设项。

outlineColor

outlineColor(value: ResourceColor | EdgeColors)

设置元素的外描边颜色。

卡片能力: 从API version 11开始,该接口支持在ArkTS卡片中使用。

系统能力: SystemCapability.ArkUI.ArkUI.Full

参数:

参数名 类型 必填 说明
value ResourceColor | EdgeColors 设置元素的外描边颜色。
默认值:Color.Black。

outlineRadius

outlineRadius(value: Dimension | OutlineRadiuses)

设置元素的外描边圆角半径。

卡片能力: 从API version 11开始,该接口支持在ArkTS卡片中使用。

系统能力: SystemCapability.ArkUI.ArkUI.Full

参数:

参数名 类型 必填 说明
value Dimension | OutlineRadiuses 设置元素的外描边圆角半径,不支持百分比。
默认值:0。
最大生效值:组件width/2 + outlineWidth或组件height/2 + outlineWidth。

OutlineOptions对象说明

名称 类型 必填 说明
width Dimension | EdgeOutlineWidths 设置外描边宽度,不支持百分比。
默认值:0,外描边效果width为必设项,否则不显示外描边。
color ResourceColor | EdgeColors 设置外描边颜色。
默认值:Color.Black。
radius Dimension | OutlineRadiuses 设置外描边圆角半径,不支持百分比。
默认值:0。
最大生效值:组件width/2 + outlineWidth或组件height/2 + outlineWidth。
style OutlineStyle | EdgeOutlineStyles 设置外描边样式。
默认值:OutlineStyle.SOLID。

EdgeOutlineWidths对象说明

引入该对象时,至少传入一个参数。

名称 参数类型 必填 描述
left Dimension 左侧外描边宽度。
right Dimension 右侧外描边宽度。
top Dimension 上侧外描边宽度。
bottom Dimension 下侧外描边宽度。

EdgeColors对象说明

引入该对象时,至少传入一个参数。

名称 参数类型 必填 描述
left ResourceColor 左侧外描边颜色。
right ResourceColor 右侧外描边颜色。
top ResourceColor 上侧外描边颜色。
bottom ResourceColor 下侧外描边颜色。

OutlineRadiuses对象说明

引用该对象时,至少传入一个参数。

名称 参数类型 必填 描述
topLeft Dimension 左上角圆角半径。
topRight Dimension 右上角圆角半径。
bottomLeft Dimension 左下角圆角半径。
bottomRight Dimension 右下角圆角半径。

EdgeOutlineStyles对象说明

引入该对象时,至少传入一个参数。

名称 参数类型 必填 描述
left OutlineStyle 左侧外描边样式。
right OutlineStyle 右侧外描边样式。
top OutlineStyle 上侧外描边样式。
bottom OutlineStyle 下侧外描边样式。

示例

// xxx.ets
@Entry
@Component
struct OutlineExample {
  build() {
    Column() {
      Flex({ justifyContent: FlexAlign.SpaceAround, alignItems: ItemAlign.Center }) {
        // 线段
        Text('DASHED')
          .backgroundColor(Color.Pink)
          .outlineStyle(OutlineStyle.DASHED).outlineWidth(5).outlineColor(0xAFEEEE).outlineRadius(10)
          .width(120).height(120).textAlign(TextAlign.Center).fontSize(16)
        // 点线
        Text('DOTTED')
          .backgroundColor(Color.Pink)
          .outline({ width: 5, color: 0x317AF7, radius: 10, style: OutlineStyle.DOTTED })
          .width(120).height(120).textAlign(TextAlign.Center).fontSize(16)
      }.width('100%').height(150)

      Text('.outline')
        .backgroundColor(Color.Pink)
        .fontSize(50)
        .width(300)
        .height(300)
        .outline({
          width: { left: 3, right: 6, top: 10, bottom: 15 },
          color: { left: '#e3bbbb', right: Color.Blue, top: Color.Red, bottom: Color.Green },
          radius: { topLeft: 10, topRight: 20, bottomLeft: 40, bottomRight: 80 },
          style: {
            left: OutlineStyle.DOTTED,
            right: OutlineStyle.DOTTED,
            top: OutlineStyle.SOLID,
            bottom: OutlineStyle.DASHED
          }
        }).textAlign(TextAlign.Center)
    }
  }
}

zh-cn_image_0000001219982706