B4A Class Switch view (Android 4+)

Discussion in 'Additional libraries, classes and official updates' started by Erel, Mar 18, 2014.

  1. Erel

    Erel Administrator Staff Member Licensed User

    I don't recommend you to change the text. On some devices the text will not show at all.

    Seems like it is not possible to change the width.
     
  2. ivanomonti

    ivanomonti Well-Known Member Licensed User

  3. Croïd

    Croïd Active Member Licensed User

    Hi Erel,

    Is it possible reverse color for switch ? (for harmonize with maps location)

    switch.png
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    There is no simple way. It will probably be easier to use a ToggleButton with two custom images (stored in a StateListDrawable).
     
  5. Croïd

    Croïd Active Member Licensed User

    OK Erel Thanks
     
  6. Dave O

    Dave O Active Member Licensed User

    I'm using this switch to replace a checkbox in an Android 5+ app.

    I'm more familiar with using libraries than classes in B4A, so I downloaded the zip file and compiled it to a library as is. Then I added the library to my app.

    The switch shows up fine and works, but no text appears, even though I set the Text property in the designer.

    The switch responds to taps in the area left of the switch control itself, so it looks like that's where the text should appear.

    So, I tried setting Text in code, but there is no Text property, just TextOn and TextOff (which apparently have been deprecated in Android 5+).

    Is there a way to get the text to show up beside the switch? I'd prefer to use the switch over a checkbox, per the Material Design guidelines.

    Thanks!
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Note that Switch is available in the ViewsEx library.

    Switch doesn't show any text. You can use a label together with the Switch.

    [​IMG]
     
    Dave O likes this.
  8. Dave O

    Dave O Active Member Licensed User

    OK thanks, that's good to know that it's different from a checkbox when it comes to the text.

    It looks like the switch itself renders at the far right of the view's bounds, so I've set the switch's width to overlap a separate label. With the switch on top (z order), that means that the user can tap the switch or the label and I can handle this with just the switch's event listener.

    As a bonus, the switch picks up the custom theme colors I'm using in the app.

    Thanks Erel!
     
  9. BarryW

    BarryW Active Member Licensed User

    Where is the sample?
     
  10. DonManfred

    DonManfred Expert Licensed User

    You need an example for a simple view with one property?

    Open the designer, add the custom view, save the layout and load it in your activity.
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    Note that Switch is now part of ViewsEx library. It is recommended to use that library instead.
     
  12. BarryW

    BarryW Active Member Licensed User

    Bcuz i cant set the text on and off
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    On new devices there is no text in the Switch control.

    [​IMG]
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice