Android Question Convert text string to b4a color

vecino

Well-Known Member
Licensed User
Longtime User
Hello, I'm having a lot of trouble to do something simple:
In an import I get a string of text, for example, like this: "$0000FFFF"
How can I convert that text string to b4a color number?
Thank you very much.
 

KMatle

Expert
Licensed User
Longtime User
As B4A uses RGB values like this (The first 255 is the alpha value)

B4X:
Activity.Color=Colors.ARGB(255,100,149,237)

You need to convert the hex values to integers

B4X:
dim hex as String
dim intValue as Int
hex = "FF"
intValue = Bit.ParseInt(hex, 16);

Remove the '$' and use a loop to get 2 chars each for the conversion.

Nice tool: https://www.w3schools.com/colors/colors_converter.asp
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…