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)

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

In addition to this answer, which is correct. You may find this stackoverflow.com/questions/5248583/… helpful. The Color class can help you parse the string based hex-color format.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.