How can i convert color code in integer ex: 13369395 to android specific. Since 13369395 is also an integer i tried doing
mainLayout.setTextColor(13369395);
but its not working.
I also tried converting 13369395 to hexadecimal like:
mainLayout.setBackgroundColor(Integer.parseInt(13369395 +"", 16)+0xFF000000);
but it also didn't help.
So far I use the following to get the RGB values from it: // rgbs is an array of integers, every single integer represents the // RGB values combined in some way int r = (int) ((Math. pow(256,3) + rgbs[k]) / 65536); int g = (int) (((Math. pow(256,3) + rgbs[k]) / 256 ) % 256 ); int b = (int) ((Math.
The four components of a color int are encoded in the following way: int color = (A & 0xff) << 24 | (R & 0xff) << 16 | (G & 0xff) << 8 | (B & 0xff);
You can also use a color resource when a drawable resource is expected in XML (for example, android:drawable="@color/green" ). The value always begins with a pound (#) character and then followed by the Alpha-Red-Green-Blue information in one of the following formats: #RGB. #ARGB.
I got the solution. Just a work around with Hexadecimal as below:
Integer.toHexString(colour);
Which returns the hexadecimal string for your integer, again if you just use it by
mainLayout.setBackgroundColor(Integer.parseInt(hexVal,16));
it wont work. You need to add mask as
mainLayout.setBackgroundColor(0xff000000 + Integer.parseInt(hexVal,16));
This has resolved the problem
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