1

Is it possible to use another file other than attrs.xml to store a specific set of attributes like colors?

Now:

attrs.xml

I want to split into:

attrs.xml
colors.xml
Seraphim's
  • 12,559
  • 20
  • 88
  • 129

1 Answers1

2

Yes, of course you can, just define a colors.xml in your values folder and place there your desired colors like so:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="my_blue">#c00e</color>
<color name="my_welcome_color">#3399cc</color>
<color name="my_transperent_white">#afff</color>
....
</resources>
Emil Adz
  • 40,709
  • 36
  • 140
  • 187
  • So are you saying that all xml files will be intepreted for the contant and not for the file name? – Seraphim's Jun 20 '13 at 12:59
  • 1
    color.xml is a special file that is recognized by android at compile time, and the colors you will define there will be defined automaticly in you self generated R file under the "public static final class color" part, so you will have access to them. – Emil Adz Jun 20 '13 at 13:01
  • 1
    Correct me if I'm wrong, but all files inside the res-folder are evaluated. And all xml-files will be parsed. So everything inside the res-folder is added to your generated R.java. – Jelle Jun 20 '13 at 13:04
  • 1
    yes you right, but for my understanding if you define you color in the attrs file then they will be placed under the "public static final class attr" section, while placing them in the colors file will place them under the "public static final class color" (I need to check this out, actually I never used the attrs file to define colors, but this is my guess). for you as a developer this does not makes any difference. – Emil Adz Jun 20 '13 at 13:08
  • Can I do it also for dimen? – Seraphim's Jun 20 '13 at 13:46
  • 1
    yes, you can, look here: http://stackoverflow.com/questions/3885164/storing-dimensions-in-xml-file-in-android – Emil Adz Jun 20 '13 at 13:48