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)
The returned color is in #AARRGGBB format, AA is the alpha value. This is described at the very beginning of this document: document link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With