B4J Question Default color

red30

Well-Known Member
Licensed User
Longtime User
I have Textfield and i change its color. Then I need to return its default color(white background with grey frame) but I cant (there is no frame). How to do?
 

Attachments

  • test5.zip
    315.9 KB · Views: 200

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
i usually do it like this:

B4X:
'Save the default style
dim normalStyle as string =txt.style

'Change style
txt.style = $"
           -fx-background-color: 
           #000000,
           linear-gradient(#7ebcea, #2f4b8f),
           linear-gradient(#426ab7, #263e75),
           linear-gradient(#395cab, #223768);
        "$

'Return to default style
txt.Style = normalStyle
 
Upvote 0

red30

Well-Known Member
Licensed User
Longtime User
Erel, could you give an example how to use CSSUtils to set default style?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
@Enrique Gonzalez R code is correct. Based on it:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private TextField1 As TextField
   Private Button1 As Button
   Private Button2 As Button
   Private defaultStyle As String
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   MainForm.Show
   defaultStyle = TextField1.Style
End Sub

Sub Button1_Action
   CSSUtils.SetBackgroundColor(TextField1,fx.Colors.ARGB(127,255,0,0))
End Sub

Sub Button2_Action
   TextField1.Style = defaultStyle
End Sub
 
Upvote 0
Top