Hex to Android colors.xml converter

Paste hex colours with names and get colors.xml, a values-night file and Compose Color(0xAARRGGBB) constants. Android puts alpha first and CSS puts it last, so 8-digit values are converted rather than copied, and each resource name is checked.

Updated

Same names as above. Colours without a dark variant fall back to values/colors.xml.

Only 4 and 8 digit values are ambiguous. 3 and 6 digit ones are opaque in both. 0x… literals are always AARRGGBB.

Brand Primary and brandPrimary become brand_primary. Turn off to be told about each bad name instead.

Android reads #RRGGBB as fully opaque. The default writes the explicit #FFRRGGBB, as Android Studio's templates do.

Colours converted

5 colours

3 with a dark variant

brand_primary
brandSecondary
surface_tint
scrim
color_b00020
brand_primary night
brandSecondary night
surface_tint night

res/values/colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="brand_primary">#FF6200EE</color>
    <color name="brandSecondary">#FF03DAC5</color>
    <color name="surface_tint">#FFFFFFFF</color>
    <color name="scrim">#80000000</color>
    <color name="color_b00020">#FFB00020</color>
</resources>
The same colours in each byte order
NameAs enteredAndroid #AARRGGBBCSS #RRGGBBAAComposeOpacity
brand_primary#6200EE#FF6200EE#6200EEColor(0xFF6200EE)100%
brandSecondary#03DAC5#FF03DAC5#03DAC5Color(0xFF03DAC5)100%
surface_tint#FFFFFF#FFFFFFFF#FFFFFFColor(0xFFFFFFFF)100%
scrim#00000080#80000000#00000080Color(0x80000000)50%
color_b00020#B00020#FFB00020#B00020Color(0xFFB00020)100%
brand_primary (night)#BB86FC#FFBB86FC#BB86FCColor(0xFFBB86FC)100%
brandSecondary (night)#03DAC6#FF03DAC6#03DAC6Color(0xFF03DAC6)100%
surface_tint (night)#121212#FF121212#121212Color(0xFF121212)100%
  • 2 colour(s) have no dark variant, so values-night/colors.xml leaves them out and Android uses the values/ colour in dark mode.
  • Renamed to valid resource names: Surface Tint → surface_tint.
  • 1 colour(s) had no name, so they are called color_ plus their hex. Give them meaningful names (what it is for, not what it looks like) before shipping.
  • 1 value(s) have 8 digits and were read as #RRGGBBAA (CSS order, alpha last). If the other order was meant, change “4 and 8 digit input” above.
  • Colours with alpha are written with the alpha first for Android and Compose and last for CSS. 0x80 is about 50% opacity.
  • Some names contain uppercase letters. Most Android projects write resource names in lowercase_with_underscores, so consider renaming them.

How are hex colours converted for Android?

Android puts the alpha channel first. A colour resource is #AARRGGBB, so #80FF6200 is a 50% opaque orange. CSS puts alpha last: the same colour is #FF620080. Both accept the short and opaque forms #RGB and #RRGGBB, so only 4-digit and 8-digit values are ambiguous, and the same eight characters mean different colours in the two orders. That is why this page asks how your input is written. A scrim written as #00000080 in a design tool is 50% black in CSS order; read as Android order it would be a nearly transparent colour with red 0, green 0, blue 0x80, which is a dark blue. The tool converts, it doesn't guess.

res/values/colors.xml holds one <color name="..."> element per colour. The name becomes the resource ID, referenced as @color/name in XML and R.color.name in code, so it has to be a valid identifier: letters, digits and underscores, not starting with a digit and not a Java keyword. A space or a hyphen can't be part of an identifier, so this tool rejects them, and “Fix invalid resource names” turns Surface Tint into surface_tint.

Dark mode uses the night qualifier. Colours in res/values-night/colors.xml replace the ones with the same name in res/values/colors.xml when the device is in night mode, and any name missing from values-night simply falls back to the default. The default file should always define every name, because a resource that exists only in a qualified folder can crash at runtime on a configuration that doesn't match it.

In Jetpack Compose the same colour is a Kotlin Long: Color(0xFF6200EE). The leading FF is alpha, so a 6-digit hex colour needs FF put in front of it. Forgetting that gives Color(0x6200EE), which is alpha 0 and draws nothing.

CSS      #RRGGBBAA   #FF620080
Android  #AARRGGBB   #80FF6200   (colors.xml)
Compose  0xAARRGGBB  Color(0x80FF6200)
opacity  alpha / 255   0x80 = 128 = 50.2%

Which hex formats does each platform accept?

Digit counts and meaning in Android colors.xml, Compose and CSS
DigitsAndroid colors.xmlCSSCompose Color(0x…)
3#RGB, opaque#RGB, opaquenot used
4#ARGB (alpha first)#RGBA (alpha last)not used
6#RRGGBB, opaque#RRGGBB, opaquewrite 0xFF then the six digits
8#AARRGGBB (alpha first)#RRGGBBAA (alpha last)0xAARRGGBB (alpha first)
5, 7, otherrejected by the resource compilerinvalidn/a

How to convert hex colours to Android colors.xml

  1. 1
    Paste your coloursOne per line, as name: #6200EE. A bare #6200EE works too and gets a generated name. You can also paste lines from an existing colors.xml or from Compose.
  2. 2
    Say how 8-digit values are writtenChoose #RRGGBBAA if they come from CSS or a design tool, #AARRGGBB if they are already Android order. 6-digit colours are the same in both.
  3. 3
    Add dark variants if you have themUse the same names. Choose the values-night output to get the second file.
  4. 4
    Copy the output into your projectSave the XML as res/values/colors.xml (and res/values-night/colors.xml), or paste the Compose constants into Color.kt. The table shows each colour in all three byte orders.

Frequently asked questions

Why is my colour transparent or the wrong colour after pasting a web hex into colors.xml?
An 8-digit web colour has alpha at the end, Android expects it at the start. #6200EE80 pasted as is becomes alpha 0x62, red 0x00, green 0xEE, blue 0x80: a different colour. Convert it to #806200EE, which is what this page does when the input order is set to CSS.
Can an Android colour resource name contain a hyphen or a space?
Not if you want it to be safe. The name becomes R.color.<name> in code, so this tool only accepts letters, digits and underscores, not starting with a digit. brand-primary and brand primary are rejected (or turned into brand_primary if the fix option is on). Java keywords such as class are rejected too, because R.color.class would not compile.
Do I need #FF in front of a 6-digit colour in colors.xml?
No. Android reads #RRGGBB as fully opaque, and #FFRRGGBB means the same. Android Studio's templates write the long form, which is why it is the default here; the option for #RRGGBB just makes the file shorter.
What happens to colours that are only defined in values-night?
Android looks the name up in the night folder first and falls back to values/. If a name exists only in values-night it has no default, and the app can crash with a resource-not-found error when the device leaves night mode, so define every name in values/colors.xml too.
How do I get opacity into a Compose colour?
Either bake alpha into the literal, Color(0x80FF6200) for 50%, or keep the opaque colour and call .copy(alpha = 0.5f). The second keeps one constant for every opacity you need.
Why does Compose need 0xFF before the colour?
Color(Long) reads the literal as 0xAARRGGBB. Color(0x6200EE) has alpha 0, which renders as invisible, so a 6-digit colour needs 0xFF in front: Color(0xFF6200EE).

Sources

Related tools

See all 135 free tools

Need a custom dev tool for your team?

We build internal tools, dashboards, APIs, and SaaS platforms. If you can describe it, we can ship it.

Built by CountryDevs · No signup · No ads · We count visits, never what you enter