5

I have set a color in my resource colors.xml file. This works fine for TextViews etc

<color name="medsListItem">#980000</color>

I am building some html/ strings in code and wanted to use same colors as in my app and keep everything well organised

I am using the code below to get the color from the resource above

String colorToUse = (String) getResources().getString(R.color.medsListItem);

the string produced however is #ff980000 Android is adding ff into my string at characters 2 and 3 (or replacing # with #ff at front of string). I can get around this by adding another line in code

colorToUse = "#" + colorToUse.substring(3, 9);

but I think I am missing something as it is (a) inelegant and (b) I do not know why the ff is being added (guessing it is to do with how android handles the color value)

Nick R
  • 51
  • 1
  • 3

1 Answers1

1

The returned color is in #AARRGGBB format, AA is the alpha value. This is described at the very beginning of this document: document link

kosa
  • 65,990
  • 13
  • 130
  • 167
user1234567
  • 1,832
  • 1
  • 18
  • 25
  • In addition to this answer, which is correct. You may find this http://stackoverflow.com/questions/5248583/android-how-to-get-a-color-from-hexadecimal-color-string helpful. The Color class can help you parse the string based hex-color format. – Knossos Jan 13 '12 at 12:24