Clone this repo:
  1. 88b97e1 DO NOT MERGE by Xin Li · 4 months ago master oreo-mr1-iot-release android-o-mr1-iot-release-1.0.10 android-o-mr1-iot-release-1.0.7 android-o-mr1-iot-release-1.0.8 android-q-preview-1
  2. 1d0cbe2 Merge Android Pie into master am: af7f8a98ad am: 1145c152b2 by Xin Li · 8 months ago android-o-mr1-iot-release-smart-display-r4 android-o-mr1-iot-release-smart-display-r5 android-wear-8.0.0_r2
  3. 1145c15 Merge Android Pie into master am: af7f8a98ad by Xin Li · 8 months ago
  4. af7f8a9 Merge Android Pie into master by Xin Li · 8 months ago master-cuttlefish-testing-release oreo-mr1-1.2-iot-release android-o-mr1-iot-release-1.0.3 android-o-mr1-iot-release-1.0.4 android-o-mr1-iot-release-1.0.5 android-o-mr1-iot-release-smart-display-r3
  5. 1be06cb release-request-849a3dc3-db53-4e70-9b7a-92295133ddeb-for-git_pi-release-4346747 snap-temp-L27900000104043986 by android-build-team Robot · 1 year, 6 months ago pie-cts-release pie-cuttlefish-testing pie-gsi pie-platform-release pie-r2-release pie-r2-s1-release pie-r2-s2-release pie-release pie-release-2 pie-s2-release pie-vts-release android-9.0.0_r1 android-9.0.0_r10 android-9.0.0_r17 android-9.0.0_r18 android-9.0.0_r2 android-9.0.0_r3 android-9.0.0_r5 android-9.0.0_r6 android-9.0.0_r7 android-9.0.0_r8 android-9.0.0_r9 android-cts-9.0_r1 android-cts-9.0_r2 android-cts-9.0_r3 android-cts-9.0_r4 android-cts-9.0_r5 android-cts-9.0_r6 android-cts-9.0_r7 android-vts-9.0_r4 android-vts-9.0_r5 android-vts-9.0_r6 android-vts-9.0_r7 android-wear-9.0.0_r1 android-wear-9.0.0_r2 android-wear-9.0.0_r3

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"?>
    <color name="hardcoded_color">#FFFFFF</color>

Layout files

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


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

Style files

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

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


Please check the following table for more available options.

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