Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
OnOffSwitch needs updating #2556
The OnOffSwitch UI component needs updating.
It has not kept up with the evolution of on/off switches especially on Android. Attached is an Android 8.0 settings panel which shows two on/off switches, one in each state.
CodenameOne is still generating separate On/Off buttons on Android which take up a lot of space.
The code of a Material design look and fill (by default) OnOffSwitch that you can use as a starting point for your rewrite of this component:
I had to remove and change a few stuff that depend on my own version of CN1 (mostly the support of dp and sp units and the usage of my own system of animations) to make it fully compatible with the official CN1 (tell me if you have import issues, I may have missed some) but it still should be a good starting point for a rewrite of the OnOffSwitch component.
@ramsestom Thanks for the component. I used it as a basis for https://github.com/codenameone/CodenameOne/blob/master/CodenameOne/src/com/codename1/components/Switch.java
The new Switch component supports Android and iOS native themes out of the box, and styling it for other platforms should be significantly easier than the old switch. The iOS7Theme and android_holo_theme include fairly close replicas of iOS and Android native switches. I have provided reference styling for the other themes (legacy iOS and Android, and UWP) that don't match their native switches exactly, but still look good.
That javadocs include details on how to customize the rendering of this component using styles and theme constants.