鸿蒙ArkTS声明式开发:跨平台支持列表【前景色设置】 通用属性 电子说
设置组件的前景色。
说明:
开发前请熟悉鸿蒙开发指导文档 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md]
从API Version 10开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
| 名称 | 参数类型 | 描述 |
|---|---|---|
| foregroundColor | [ResourceColor] | [ColoringStrategy] |
// xxx.ets
@Entry
@Component
struct ForegroundColorExample {
build() {
Column({ space: 100 }) {
// 绘制一个直径为150的圆,默认填充色为黑色
Circle({ width: 150, height: 200 })
// 绘制一个直径为150的圆,
Circle({ width: 150, height: 200 }).foregroundColor(Color.Red)
}.width('100%').backgroundColor(Color.Blue)
}
}

// xxx.ets
@Entry
@Component
struct ColoringStrategyExample {
build() {
Column({ space: 100 }) {
// 绘制一个直径为150的圆,默认填充色为黑色
Circle({ width: 150, height: 200 })
// 绘制一个直径为150的圆,设置前景色为组件背景色的反色
Circle({ width: 150, height: 200 })
.backgroundColor(Color.Black)
.foregroundColor(ColoringStrategy.INVERT)
}.width('100%')
}
}


`HarmonyOS与OpenHarmony鸿蒙文档籽料:mau123789是v直接拿`
// xxx.ets
@Entry
@Component
struct foregroundColorInherit {
build() {
Column() {
Button('设置前景色为橘色').fontSize(20).foregroundColor(Color.Orange).backgroundColor(Color.Gray)
Divider()
Button('未设置前景色继承自父组件').fontSize(20).backgroundColor(Color.Gray)
}.foregroundColor(Color.Red)
}
}

审核编辑 黄宇
全部0条评论
快来发表一下你的评论吧 !