This is a warning.
| |
Invalid Color hex value | |
Warning | |
Correctness | |
Any | |
Jetpack Compose | |
androidx.compose.ui.graphics | |
Lint 8.0 and 8.1 | |
Lint 8.7+ | |
1.5.0 | |
Kotlin and Java files and test sources | |
This check runs on the fly in the IDE editor | |
2021 |
Here is an example of lint warnings produced by this check:
src/test/test.kt:6:Warning: Invalid Color hex value
[InvalidColorHexValue]
val color = Color(0x00000)
-------
src/test/test.kt:7:Warning: Invalid Color hex value
[InvalidColorHexValue]
val color2 = Color(0xEEEEE)
-------
src/test/test.kt:8:Warning: Invalid Color hex value
[InvalidColorHexValue]
val color3 = Color(0x00_0_0_0L)
-----------
Here is the source file referenced above:
src/test/test.kt
:
package test
import androidx.compose.ui.graphics.*
val color = Color(0x00000)
val color2 = Color(0xEEEEE)
val color3 = Color(0x00_0_0_0L)
You can also visit the source code for the unit tests for this check to see additional scenarios.
The above example was automatically extracted from the first unit test
found for this lint check, ColorDetector.incorrectChannels
.
To report a problem with this extracted sample, visit
https://issuetracker.google.com/issues/new?component=612128.
// build.gradle.kts
implementation("androidx.compose.ui:ui-graphics-android:1.9.0-alpha01")
// build.gradle
implementation 'androidx.compose.ui:ui-graphics-android:1.9.0-alpha01'
// build.gradle.kts with version catalogs:
implementation(libs.ui.graphics.android)
# libs.versions.toml
[versions]
ui-graphics-android = "1.9.0-alpha01"
[libraries]
# For clarity and text wrapping purposes the following declaration is
# shown split up across lines, but in TOML it needs to be on a single
# line (see https://github.com/toml-lang/toml/issues/516) so adjust
# when pasting into libs.versions.toml:
ui-graphics-android = {
module = "androidx.compose.ui:ui-graphics-android",
version.ref = "ui-graphics-android"
}
1.9.0-alpha01 is the version this documentation was generated from; there may be newer versions available.
NOTE: These lint checks are also made available separate from the main library.
You can also use androidx.compose.ui:ui-graphics-lint:1.9.0-alpha01
.
Additional details about androidx.compose.ui:ui-graphics-android.
You can suppress false positives using one of the following mechanisms:
// Kotlin
@Suppress("InvalidColorHexValue")
fun method() {
Color(...)
}
or
// Java
@SuppressWarnings("InvalidColorHexValue")
void method() {
Color(...);
}
//noinspection InvalidColorHexValue
problematicStatement()
lint.xml
file in the source tree which turns off
the check in that folder and any sub folder. A simple file might look
like this:
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<issue id="InvalidColorHexValue" severity="ignore" />
</lint>
Instead of ignore
you can also change the severity here, for
example from error
to warning
. You can find additional
documentation on how to filter issues by path, regular expression and
so on
here.
lintOptions {
disable 'InvalidColorHexValue'
}
In Android projects this should be nested inside an android { }
block.
lint
, using the --ignore
flag:
$ lint --ignore InvalidColorHexValue ...`