B4J Library B4j ToggleSwitch

This is a simple start for a Toggleswitch Customview for B4j. It is deliberately not a B4X Customview as I wanted it to be styleable via CSS.

upload_2018-11-6_22-42-44.png

The animation duration is set, but you could very easily add a designer property to allow changing it in the Designer. The 3 components can be styled in the css file included in the project.

Don't forget to add the Stylesheet to an appropriate place.
 

Attachments

  • ToggleSwitch.zip
    3.4 KB · Views: 444
Last edited:

stevel05

Expert
Licensed User
Longtime User
Hi Roger,

This thread just contains a very basic implementation that anybody can use as a template and change as they wish. If you want to share your modified version, feel free to do so in a new thread and explain what you have changed.

BTW, there is a small error (check the log window) that should be addressed before you share it.
 

ThRuST

Well-Known Member
Licensed User
Longtime User
ok I should update my previous post, sorry for taking advantage of your code.
I do like my addions, it made it a bit better in fact :)
 

ThRuST

Well-Known Member
Licensed User
Longtime User
What bug are you talking about? Both of our code is perfect. Or are you trying to tell me something else?
What if I'm Tuco's brother in Breakin' bad Steve (Netflix success TV series) hahaha
 

ThRuST

Well-Known Member
Licensed User
Longtime User
Oops sorry I totally missed that. Thanks for notifying me. I will update my post with v1.1
 

ThRuST

Well-Known Member
Licensed User
Longtime User
Hi Steve. I updated my changes to v1.2 which should be the best yet.
 

ThRuST

Well-Known Member
Licensed User
Longtime User
Hi again Steve, I couldn't let go of it. I updated your library to v1.3 :D

See my post #19 to find it.
 

ThRuST

Well-Known Member
Licensed User
Longtime User
Steve, it would be nice with a fading effect on the text everytime the button is clicked. How to do that :rolleyes:
 

ThRuST

Well-Known Member
Licensed User
Longtime User
Steve, do you mind adding calls to these subs in your class. It will save me alot of time if you do it. Thanks

B4X:
Public Sub FadeIn
    TSLbl.SetAlphaAnimated(mDuration /2, 1)
End Sub

Public Sub FadeOut
    TSLbl.SetAlphaAnimated(mDuration /2, 0)
End Sub
 

VittorioBarile

Member
Licensed User
Hi, I'm trying to use your lib on B4X Pages project.
In my first page it works, but when i close it and open another B4XPage, it doens't show button switch:

in my AppStart it works, but when i close this layout and open a new one it doesn't show button switch, but only text!

AppStart:
MainForm = Form1
MainForm.Stylesheets.Add(File.GetUri(File.DirAssets,"ToggleSwitch.css"))
MainForm.Show

OnClick new page:
B4XPages.ShowPageAndRemovePreviousPages("NewPage")

could you help me?
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
Sorry I somehow missed this post, did you get it fixed? If not post a project showing the problem.
 

stevel05

Expert
Licensed User
Longtime User
Just a thought, did you add the stylesheet to the form in the new page?
 
Top