B4J Question Is there a way to dim a view's color when it is disabled?

Diceman

Active Member
Licensed User
I noticed when a view is disabled, its color does not change. So the user has to click on the view to see if it is enabled. This is going to frustrate the user and increase requests to tech support.
Other software I've used like Delphi will automatically dim the view when it is disabled. Is there a way to achieve this in B4J? Can I assume B4A and B4i also do not dim disabled views?

I have attached a small program that demonstrates this.

TIA
 

Attachments

  • TestEnabled.zip
    2.6 KB · Views: 160

Chris2

Active Member
Licensed User
Longtime User
With most views you can set the alpha level when you disable it to achieve what you want;
B4X:
button.Enabled=False
button.Alpha = 0.5
'or
button.SetAlphaAnimated(300, 0.5)
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Javafx is css based so you can change the behaviour by adding a css file to the project (see attached). The default css is moderna.css.

B4a certainly does change the views appearance when disabled (I tested it by converting your example).
 

Attachments

  • TestEnabled2.zip
    2.9 KB · Views: 143
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
That got me reading the moderna css, it seems to have a default of setting the opacity to 0.4. which doesn't seem to carry through.

It's simple enough to recreate by copying the disabled things block (or as much as you need) from the moderna css, to your own style sheet. Or you could handle it programmatically as Chris2 suggested.
 

Attachments

  • TestEnabled3.zip
    3.2 KB · Views: 171
Last edited:
Upvote 0

Diceman

Active Member
Licensed User
Thanks guys for your replies.

Chris2's suggestion is a quick solution when disabling a single control, by changing the view's alpha when I disable the view using code. Kudos for that.
stevel05's solution will work for the entire application by adding just one line of code. So that's likely the solution I will go with.

A couple of quick questions though.

1) Thanks for that list of CSS properties. Is there a link at the B4X site for this? I did find something similar at WheelerCode.WordPress.com
2) Is it possible to create an Id Style in the CSS file and have the B4X view reference it? For example, can I put the "#font-button" Id Style name in the "Extra CSS" property using the Designer? Or do I have to hard code the text (below) into this property (which makes it more difficult to maintain)?

B4X:
#font-button {
    -fx-font: bold italic 20pt "Arial";
    -fx-effect: dropshadow( one-pass-box , black , 8 , 0.0 , 2 , 0 );
}

TIA
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
For question 2, not directly. You could manipulate one of the free text fields in the designer to do what you want. tag is probably the safest. (see attached)
Or you could create customviews to wrap each view you want to use and add the ID and Styleclass fields which is a little more complicated.
 

Attachments

  • TestEnabled4.zip
    3.5 KB · Views: 183
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…