B4J Question CSSUtils changing text colour [Solved]

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All,

I am attempting change the text colours of buttons as they are actioned. The code below should toggle the text colours of two buttons but it doesn't. :mad:

Code: Copy
Sub BtnStandard_Action
    CSSUtils.SetStyleProperty(BtnStandard, "fx-text-fill", "#0D88BF")   'Change button text colour
    CSSUtils.SetStyleProperty(BtnExtended, "fx-text-fill", "LightGray")   'Change button text colour
    Mode = 0
    StandardExtended.Initialize("StandardExtended", 5)         '5ms timer
    StandardExtended.Enabled = True
End Sub

Sub BtnExtended_Action
    CSSUtils.SetStyleProperty(BtnExtended, "fx-text-fill", "#0D88BF")   'Change button text colour
    CSSUtils.SetStyleProperty(BtnStandard, "fx-text-fill", "LightGray")   'Change button text colour
    Mode = 1
    StandardExtended.Initialize("StandardExtended", 5)         '5ms timer
    StandardExtended.Enabled = True
    VolReqSCalc
    ConcVolSCalc
    Validate
End Sub

I have obviously missed something in the CCSUtils tutorial, can anyone spot the error?

Regards Roger
 
Do you want that the text color will be different only when the button is clicked? You should use a CSS file for this. See this example: https://www.b4x.com/android/forum/threads/css-example.35854/#content
I think I have failed to communicate the problem.

Two buttons: One blue text to indicate active state. Second button lightgray to indicate inactive state.
Click on second button: Text on second button turns blue [Active state]. Text on first button turns lightgray [Inactive state]
Click on first button: Colours toggle back to original colours/states.

Regards Roger
 
Upvote 0
I'm sorry but I don't understand your code. What is this timer doing? Why do you create a new timer each time?

Why is the interval so short?

You should upload a small example and then we can better help you.

Hi Erel,

Deja vu, you have seen this project before in the B4A version. The project is not large so I will upload it as is.
Please remember it is a WIP and therefore messy.
The issue at the moment is that the text not changing colour on the Standard and Extended buttons. [Timer not relevent]
The colours on the Metric, Imp and U.S. buttons change but I have yet change that code to CSSUtils as you suggested in a different post.
As usual any help much appreciated.

Regards Roger
 

Attachments

Upvote 0
This is the solution:

SS-2016-07-31_18.05.50.png
 
Upvote 0
This is the solution:

SS-2016-07-31_18.05.50.png


Problem solved. A new day and I see that I had ommited the - in the code line.

CSSUtils.SetStyleProperty(BtnStandard, "fx-text-fill", "#0D88BF") ' Does not work , missing -
CSSUtils.SetStyleProperty(BtnStandard, "-fx-text-fill", "#0D88BF") 'Does work when - included

Regards Roger
 
Upvote 0
Back
Top