Translate colors from text

pcbtmr

Member
Licensed User
Longtime User
Not sure how to do this. I have an array of color names (Core colors) that, upon selection of one, sets the color of a label. Preferred not to have to use If-Then's or Select Case's.
Any help much appreciated.
 

stevel05

Expert
Licensed User
Longtime User
Try this:

From Android Developers

B4X:
Sub ParseColor(Name As String) As Int

   'Will return an illegal argument exception if the color is not valid so
   'put in a Try block and log the result if in error
   
   'From Android developers Documentation:
   'Parse the color string, and return the corresponding color-int. 
   'If the String cannot be parsed, throws an IllegalArgumentException Exception. 
   'Supported formats are: #RRGGBB #AARRGGBB 'red', 'blue', 'green', 'black', 'white', 
   ''gray', 'cyan', 'magenta', 'yellow', 'lightgray', 'darkgray'
   
   Try
      Dim R As Reflector
      Return R.RunStaticMethod("android.graphics.Color","parseColor",Array As Object(Name),Array As String("java.lang.String"))
   Catch
      Log(LastException)
   End Try
End Sub
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…