Clone this repo:
  1. af7f8a9 Merge Android Pie into master by Xin Li · 7 weeks ago master oreo-mr1-iot-release android-o-mr1-iot-release-1.0.3 android-o-mr1-iot-release-1.0.4
  2. ec3da48 Update error message in color check. by jackqdyulei · 1 year ago pie-dev
  3. 7894d58 Disable LintError in color check by jackqdyulei · 1 year ago
  4. 11b0281 Add color lint check in prebuilts/checkcolor by jackqdyulei · 1 year, 9 months ago
  5. f6f661b Initial empty repository by Bill Rassieur · 1 year, 9 months ago o-iot-preview-5 o-mr1-iot-preview-6 o-mr1-iot-preview-7 o-mr1-iot-preview-8 oreo-cts-release oreo-dev oreo-dr1-dev oreo-dr1-release oreo-dr2-release oreo-dr3-release oreo-m2-release oreo-m2-s1-release oreo-m2-s2-release oreo-m2-s3-release oreo-m2-s4-release oreo-m2-s5-release oreo-m3-release oreo-m4-s1-release oreo-m4-s10-release oreo-m4-s11-release oreo-m4-s12-release oreo-m4-s2-release oreo-m4-s3-release oreo-m4-s4-release oreo-m4-s5-release oreo-m4-s6-release oreo-m4-s7-release oreo-m4-s8-release oreo-m4-s9-release oreo-m5-release oreo-m6-s2-release oreo-m6-s3-release oreo-m6-s4-release oreo-mr1-cts-release oreo-mr1-dev oreo-mr1-release oreo-mr1-s1-release oreo-mr1-vts-release oreo-r2-release oreo-r3-release oreo-r4-release oreo-r5-release oreo-r6-release oreo-release oreo-vts-release android-8.0.0_r1 android-8.0.0_r10 android-8.0.0_r11 android-8.0.0_r12 android-8.0.0_r13 android-8.0.0_r15 android-8.0.0_r16 android-8.0.0_r17 android-8.0.0_r2 android-8.0.0_r21 android-8.0.0_r22 android-8.0.0_r23 android-8.0.0_r24 android-8.0.0_r25 android-8.0.0_r26 android-8.0.0_r27 android-8.0.0_r28 android-8.0.0_r29 android-8.0.0_r3 android-8.0.0_r30 android-8.0.0_r31 android-8.0.0_r32 android-8.0.0_r33 android-8.0.0_r34 android-8.0.0_r35 android-8.0.0_r36 android-8.0.0_r4 android-8.0.0_r7 android-8.0.0_r9 android-8.1.0_r1 android-8.1.0_r10 android-8.1.0_r11 android-8.1.0_r12 android-8.1.0_r13 android-8.1.0_r14 android-8.1.0_r15 android-8.1.0_r16 android-8.1.0_r17 android-8.1.0_r18 android-8.1.0_r19 android-8.1.0_r2 android-8.1.0_r20 android-8.1.0_r21 android-8.1.0_r22 android-8.1.0_r23 android-8.1.0_r25 android-8.1.0_r26 android-8.1.0_r27 android-8.1.0_r28 android-8.1.0_r29 android-8.1.0_r3 android-8.1.0_r30 android-8.1.0_r31 android-8.1.0_r32 android-8.1.0_r33 android-8.1.0_r35 android-8.1.0_r36 android-8.1.0_r37 android-8.1.0_r38 android-8.1.0_r39 android-8.1.0_r4 android-8.1.0_r40 android-8.1.0_r41 android-8.1.0_r42 android-8.1.0_r43 android-8.1.0_r45 android-8.1.0_r46 android-8.1.0_r5 android-8.1.0_r6 android-8.1.0_r7 android-8.1.0_r8 android-8.1.0_r9 android-cts-8.0_r1 android-cts-8.0_r10 android-cts-8.0_r11 android-cts-8.0_r12 android-cts-8.0_r13 android-cts-8.0_r2 android-cts-8.0_r3 android-cts-8.0_r4 android-cts-8.0_r5 android-cts-8.0_r6 android-cts-8.0_r7 android-cts-8.0_r8 android-cts-8.0_r9 android-cts-8.1_r1 android-cts-8.1_r2 android-cts-8.1_r3 android-cts-8.1_r4 android-cts-8.1_r5 android-cts-8.1_r6 android-cts-8.1_r7 android-cts-8.1_r8 android-cts-8.1_r9 android-o-iot-preview-5 android-o-mr1-iot-preview-6 android-o-mr1-iot-preview-7 android-o-mr1-iot-preview-8 android-o-mr1-iot-release-1.0.0 android-o-mr1-iot-release-1.0.1 android-o-mr1-iot-release-1.0.2 android-o-mr1-preview-1 android-o-mr1-preview-2 android-p-preview-1 android-p-preview-2 android-p-preview-3 android-vts-8.0_r1 android-vts-8.0_r2 android-vts-8.0_r6 android-vts-8.0_r7 android-vts-8.0_r8 android-vts-8.1_r3 android-vts-8.1_r4 android-vts-8.1_r5 android-wear-8.0.0_r1 android-wear-p-preview-2

Lint check for hardcoded colors

What is this lint check for

This check detects whether hardcoded colors have been added in a CL.

Starting in Android O, multiple device themes will exist on devices, enabling changing the look and feel of all system UI. In order to make that effort possible, colors in component that uses this check must be specified using theme attributes, rather than hardcoded colors. Otherwise, when the theme changes, this UI will not update properly.

Examples of hardcoded colors

Color files

<!-- File: res/values/colors.xml -->
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="hardcoded_color">#FFFFFF</color>
</resources>

Layout files

<!-- File: res/layout/my_layout.xml -->
<?xml version="1.0" encoding="utf-8"?>
<TextView
    android:textColor="#FF000000" />

Or

<!-- File: res/layout/my_layout.xml -->
<?xml version="1.0" encoding="utf-8"?>
<TextView
    android:textColor="@color/hardcoded_color" />

Style files

<!-- File: res/values/styles.xml -->
<style name="MyStyle">
    <item name="android:textColor">#ff3c3c3c</item>
</style>

How to fix it

Use attributes in theming as much as possible

Here are some tips to choose the colors.

Choose colors for text

Use color attributes specified in the theme. Some examples:

  1. textColorPrimary
  2. textColorSecondary
  3. colorAccent

Choose colors for icon

For vector drawable, please use full opacity color as fillColor and tint it with theme attribute. example

Others

Please check the following table for more available options.

AttributeDescription
colorAccentBright complement to the primary branding color. By default, this is the color applied to framework controls (via colorControlActivated).
colorForegroundColor for foreground imagery. Most text and image colors will be based on some alpha of colorForeground.
colorBackgroundColor of background imagery, ex. full-screen windows.
colorBackgroundFloatingColor of background imagery for floating components, ex. dialogs, popups, and cards.
colorPrimaryThe primary branding color for the app. This is the color applied to the action bar background.
colorPrimaryDarkDark variant of the primary branding color. By default, this is the color applied to the status bar (via statusBarColor) and navigation bar (via navigationBarColor).
colorErrorColor used for error states and things that need to be drawn to the users attention.
textColorPrimary (colorPrimaryText)Is now constructed out of colorForeground and primaryContentAlpha.
textColorSecondary (colorSecondaryText)Is now constructed out of colorForeground and primaryContentAlpha.

How to bypass it

We strongly discourage bypassing color lint check.

However, if you need to bypass the check, please update the baseline.xml by running following command in package root folder(i.e. package/app/Settings/)

export ANDROID_LINT_JARS=$(gettop)/prebuilts/checkcolor/checkcolor.jar
lint --check HardCodedColor --xml color-check-baseline.xml .

After update the baseline.xml, your hardcoded color will be ignored in check. Please submit the new baseline.xml within your cl.

Contact us

  1. For help to remove hardcoded colors or report issue in color check, please contact jackqdyulei@google.com