commit | 47d4cfb86c5001ef70ef9f9fbed6db04209f1775 | [log] [tgz] |
---|---|---|
author | Ember Rose <[email protected]> | Fri Feb 04 17:29:26 2022 +0000 |
committer | Automerger Merge Worker <[email protected]> | Fri Feb 04 17:29:26 2022 +0000 |
tree | 4195a8a40c9bd7c36fba36d4f782984370666e1b | |
parent | 783b39e6b8b498b4217346f5dae17b5da097990e [diff] | |
parent | 383d3e0bf16bb52e1c62b3044354caaab498d8fd [diff] |
Update checkcolor.py hashbang to Python 3 am: ee59816895 am: 8b7e6cc073 am: 4f8c37e10d am: 383d3e0bf1 Original change: https://android-review.googlesource.com/c/platform/prebuilts/checkcolor/+/1971582 Change-Id: I01a621d1fc21f4e6759f15f9329b11838ec882c1
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.
<!-- File: res/values/colors.xml --> <?xml version="1.0" encoding="utf-8"?> <resources> <color name="hardcoded_color">#FFFFFF</color> </resources>
<!-- 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" />
<!-- File: res/values/styles.xml --> <style name="MyStyle"> <item name="android:textColor">#ff3c3c3c</item> </style>
Here are some tips to choose the colors.
Use color attributes specified in the theme. Some examples:
textColorPrimary
textColorSecondary
colorAccent
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.
Attribute | Description |
---|---|
colorAccent | Bright complement to the primary branding color. By default, this is the color applied to framework controls (via colorControlActivated). |
colorForeground | Color for foreground imagery. Most text and image colors will be based on some alpha of colorForeground. |
colorBackground | Color of background imagery, ex. full-screen windows. |
colorBackgroundFloating | Color of background imagery for floating components, ex. dialogs, popups, and cards. |
colorPrimary | The primary branding color for the app. This is the color applied to the action bar background. |
colorPrimaryDark | Dark variant of the primary branding color. By default, this is the color applied to the status bar (via statusBarColor) and navigation bar (via navigationBarColor). |
colorError | Color 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. |
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.