B4J Question Button backround color change

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
For a specific button:

B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private Button1 As Button
End Sub

Sub AppStart (Form1 As Form, Args() As String)

    MainForm = Form1
 
    MainForm.RootPane.LoadLayout("1") 'Load the layout file.
    MainForm.Stylesheets.Add(File.GetUri(File.DirAssets, "style.css"))
    Button1.Id="button1" ' Set ID here
 
    MainForm.Show
 
End Sub

'Create a style.css file
'Using id selector

#button1:pressed {-fx-background-color:   yellow;}

Or for all buttons

B4X:
'Create a style.css file
'Using "select all" selector

.button:pressed {-fx-background-color:   yellow;}
 
Last edited:
Upvote 0

david13

Member
Licensed User
Thanks for your fast answer, it's is helpfull but i want the color to stay changed even when I stop the button presse, thanks again
 
Upvote 0

david13

Member
Licensed User
Never set the style property directly.

It should be CSSUtils.SetBackgroundColor. It is simpler and will not remove all other style attributes.
Thanks Erel, Can you write the above exemple with CSSUtils.SetBackgroundColor so I can Understand, thanks
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top