Reputation: 27670
I need to represent the hex color #F0FFF0
in an android application (stored as an integer). I am storing this as:
int color = 0xF0FFF0;
But the color seems way off when being rendered (in fact, it's black). Am I storing the color incorrectly?
Upvotes: 2
Views: 4371
Reputation: 12259
Android uses Hex ARGB values, which are formatted as #AARRGGBB. That first pair of letters, the AA, represent the Alpha Channel. You must convert your decimal opacity values to a Hexdecimal value. Here are the steps:
Alpha Hex Value Process
That's how you find the alpha channel value. I've taken the liberty to put together a list of values for you. Enjoy!
Hex Opacity Values
Upvotes: 6
Reputation: 3011
Not you didn't.
You have to add Alpha channel.
For your example is :
int color = 0xFFF0FFF0
I think it works!
Upvotes: 1
Reputation: 24667
I've always specified my colours with the alpha value, ie:
int color = 0xFFF0FFF0;
I'm not sure if the leading FF will be implicit if it's omitted however.
Upvotes: 3
Reputation: 3106
Perhaps you need to set the alpha too. ie.
int color = 0xFFF0FFF0;
where the first two FF represent the alpha as being completely opaque. See: http://developer.android.com/reference/android/graphics/Color.html
Upvotes: 6