【鸿蒙next开发】ArkUI框架:ArkTS组件-外描边设置

 往期鸿蒙5.0全套实战文章必看:(文中附带鸿蒙5.0全栈学习资料)


外描边设置

设置组件外描边(outline)样式。外描边绘制在组件的外侧,不影响布局,不会占用组件本身大小。

说明

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

outline

outline(value: OutlineOptions)

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

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

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

参数:

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

OutlineStyle11+枚举说明

外描边样式。

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

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

名称说明
SOLID显示为一条实线。
DASHED显示为一系列短的方形虚线。
DOTTED显示为一系列圆点,圆点半径为outlineWidth的一半。

outlineStyle

outlineStyle(value: OutlineStyle | EdgeOutlineStyles)

设置元素的外描边样式。

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

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

参数:

参数名类型必填说明
valueOutlineStyle | EdgeOutlineStyles

设置元素的外描边样式。

默认值:OutlineStyle.SOLID

outlineWidth

outlineWidth(value: Dimension | EdgeOutlineWidths)

设置元素的外描边宽度。

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

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

参数:

参数名类型必填说明
valueDimension | EdgeOutlineWidths

设置元素的外描边宽度,不支持百分比。

默认值:0,外描边效果width为必设项。

outlineColor

outlineColor(value: ResourceColor | EdgeColors)

设置元素的外描边颜色。

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

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

参数:

参数名类型必填说明
valueResourceColor | EdgeColors

设置元素的外描边颜色。

默认值:Color.Black。

outlineRadius

outlineRadius(value: Dimension | OutlineRadiuses)

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

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

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

参数:

参数名类型必填说明
valueDimension | OutlineRadiuses

设置元素的外描边圆角半径,不支持百分比。

默认值:0。

最大生效值:组件width/2 + outlineWidth或组件height/2 + outlineWidth。

OutlineOptions对象说明

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

名称类型必填说明
widthDimension | EdgeOutlineWidths

设置外描边宽度,不支持百分比。

默认值:0,外描边效果width为必设项,否则不显示外描边。

colorResourceColor | EdgeColors | LocalizedEdgeColors12+

设置外描边颜色。

默认值:Color.Black。

radiusDimension | OutlineRadiuses

设置外描边圆角半径,不支持百分比。

默认值:0。

最大生效值:组件width/2 + outlineWidth或组件height/2 + outlineWidth。

styleOutlineStyle | EdgeOutlineStyles

设置外描边样式。

默认值:OutlineStyle.SOLID。

EdgeOutlineWidths对象说明

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

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

名称参数类型必填描述
leftDimension左侧外描边宽度。
rightDimension右侧外描边宽度。
topDimension上侧外描边宽度。
bottomDimension下侧外描边宽度。

EdgeColors对象说明

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

元服务API: 从API version 11开始,该接口支持在元服务中使用。

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

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

名称参数类型必填描述
leftResourceColor左侧外描边颜色。
rightResourceColor右侧外描边颜色。
topResourceColor上侧外描边颜色。
bottomResourceColor下侧外描边颜色。

LocalizedEdgeColors对象说明12+

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

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

名称参数类型必填描述
startResourceColor

左侧外描边颜色。

从左至右显示语言模式下为右侧外描边颜色。

endResourceColor

右侧外描边颜色。

从左至右显示语言模式下为左侧外描边颜色。

topResourceColor上侧外描边颜色。
bottomResourceColor下侧外描边颜色。

OutlineRadiuses对象说明

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

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

名称参数类型必填描述
topLeftDimension左上角圆角半径。
topRightDimension右上角圆角半径。
bottomLeftDimension左下角圆角半径。
bottomRightDimension右下角圆角半径。

EdgeOutlineStyles对象说明

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

元服务API: 从API version 12开始,该接口支持在元服务中使用。

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

名称参数类型必填描述
leftOutlineStyle左侧外描边样式。
rightOutlineStyle右侧外描边样式。
topOutlineStyle上侧外描边样式。
bottomOutlineStyle下侧外描边样式。

示例

示例1(使用外描边属性)

该示例主要演示如何通过outline来实现组件外描边。

// 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)
    }
  }
}

示例2(使用LocalizedEdgeColors类型)

该示例将outline属性中的color属性值设置为LocalizedEdgeColors类型。

// 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: { start: '#e3bbbb', end: 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)
    }
  }
}

从左至右显示语言示例图

从右至左显示语言示例图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值