B4J Question How do I convert a Paint object to a Color string

GuyBooth

Active Member
Licensed User
Longtime User
Properties I have are being returned from a CustomView as a Paint object.


I want to be able to use the values in a CSS statement to set the text color like this:


B4X:
#DesignerProperty: Key: ActionHighlightColor, DisplayName: Action Highlight Color, FieldType: Color, DefaultValue: 0xFFFC1010

Sub Class_Globals
    Dim et as TextField
End Sub

' In Some other sub
Sub Someothersub
    AHLColor = Props.Get("ActionHighlightColor")
    CSSUtils.SetStyleProperty(et,"-fx-text-fill", AHLColor)
End Sub


As written this produces an error because the CSSUtils is looking for a string.
How to I set the text color using the paint object?
Or how do I convert the paint object to a string I can use in the CSSUtils method above?
 

Daestrum

Expert
Licensed User
Longtime User
You need to
a, lose the alpha part of the colour (and with 0xffffff)
b, make it a hex string
B4X:
 CSSUtils.SetStyleProperty(et,"-fx-text-fill", Bit.ToHexString(Bit.And(AHLColor,0xffffff)))
 
Upvote 0

GuyBooth

Active Member
Licensed User
Longtime User
mmm - this gives me this error when I try to save it:
B4X:
java.lang.NumberFormatException: For input string: "(Color) 0xb22222ff"
and the same error when I use it in the CSSUtils statement in your post.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Sorry I assumed that the color was an integer value as your default value is an integer.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…