Android Question [SOLVED] Use HEX value to set view color


Well-Known Member
Licensed User
Longtime User
This was driving me nuts! After finding this post I figured it could be done...
This will also work:
Activity.Color = 0xE4E4E2
And if you need to parse a string then:
Activity.Color = Bit.ParseInt(text.Replace("#", ""), 16)
But everything I tried resulted in just the default colour being applied, at least that's what I thought was happening. The colour values I was using were taken from the Material guidelines website.
After some serious head scratching and self-doubt, I've worked out what is wrong!
@Erel example should have be written as...
Activity.Color = 0xFFE4E4E2
Where FF is the alpha value required, either fully opaque (FF) or fully transparent (00). This might seem obvious to most of you but I gave up on it late last night and it's only with a fresh set of eyes that I've realised what I was doing wrong. Hope it helps others having similar trouble.