IARI IARI - 24 days ago 8
Android Question

Android: Is it possible to include color definitions from files in colors.xml

The color definition in the application I work in are quite complex.
Among other things:


  • there are legacy definitions

  • there are basic color definitions

  • there is a separate layer of color definitions that references the basic definitions



I would like to organize these color definitions in multipole files, possibly including each other.

(How) Is that possible?

Answer

You can define your colors in any file as long as it is in the values directory.

In your case you could do something like this:

values
|-- legacy_colors.xml
|-- basic_colors.xml
|-- high_level_colors.xml

There is no way for the files include each other, but you can reference the values from other files like that:

File: basic_colors.xml

<color name="basic_blue">#00bbff</color>

File: high_level_colors.xml

<color name="list_item_backgroud">@color/basic_blue</color>