Color values should be referenced from color.json using '$r' to adapt to different system color modes, and the use of fixed values is prohibited.
@Entry
@Component
struct Index {
build() {
RelativeContainer() {
// Color value referenced by 'sys.color.xxx'. The dark and light color modes are supported by default.
Text()
.fontColor($r('sys.color.ohos_id_color_activated'));
// Color value referenced by 'app.color.xxx', which must be configured in the color.json files for the dark and light color modes.
Text()
.fontColor($r('app.color.text_color'));
}
}
} @Entry
@Component
struct Index1 {
build() {
RelativeContainer() {
Text('message').fontColor('#000000')
Text('message').fontColor('rgb(0, 0, 0)')
Text('message').fontColor(Color.Black)
}
}
} plugin:@cross-device-app-dev/recommended plugin:@cross-device-app-dev/all
For details about how to configure Code Linter check rules, see Code Linter.