Mar 18, 2014 Replies: 52 This class wraps the native Switch view using JavaObject. This view was added in Android 4+. You can either add the view with the designer as a CustomView (don't forget to set Custom Type field) or add it by code. See the attached example. Edit: Switch is available in the ViewsEx library. Last edited: Jun 23, 2016 Click to expand...
This class wraps the native Switch view using JavaObject. This view was added in Android 4+. You can either add the view with the designer as a CustomView (don't forget to set Custom Type field) or add it by code. See the attached example. Edit: Switch is available in the ViewsEx library.
woniol Active Member Licensed User Longtime User Mar 18, 2014 #3 Thanks I was waiting for it for long time. I added two more subs for setting and getting Enabled property for this class: Code: Public Sub setEnabled(b As Boolean) joSwitch.RunMethod("setEnabled", Array As Object(b)) End Sub Public Sub getEnabled As Boolean Return joSwitch.RunMethod("isEnabled", Null) End Sub and this: Code: Switch.Enabled = base.Enabled to the DesignerCreateView Sub Last edited: Mar 18, 2014
Thanks I was waiting for it for long time. I added two more subs for setting and getting Enabled property for this class: Code: Public Sub setEnabled(b As Boolean) joSwitch.RunMethod("setEnabled", Array As Object(b)) End Sub Public Sub getEnabled As Boolean Return joSwitch.RunMethod("isEnabled", Null) End Sub and this: Code: Switch.Enabled = base.Enabled to the DesignerCreateView Sub
Olaan Expert Licensed User Longtime User Mar 18, 2014 #4 It's better than the old strategy. I like it.
Erel B4X founder Staff member Licensed User Longtime User Mar 19, 2014 #5 @woniol it is actually simpler. You can access all of the standard properties through sw.Switch. For example: Code: sw.Switch.Enabled = false
@woniol it is actually simpler. You can access all of the standard properties through sw.Switch. For example: Code: sw.Switch.Enabled = false
Olaan Expert Licensed User Longtime User Mar 19, 2014 #6 Hi all, How do I design alike iOS's ? (Angle of it have radius)
Olaan Expert Licensed User Longtime User Mar 20, 2014 #8 I mean that switch in picture post#1 is look strong,I would like to can design look like iOS's ,it look like pretty.(Can I use nine-patch with the custom view? or other strategies)
I mean that switch in picture post#1 is look strong,I would like to can design look like iOS's ,it look like pretty.(Can I use nine-patch with the custom view? or other strategies)
Erel B4X founder Staff member Licensed User Longtime User Mar 20, 2014 #9 This is how the native Switch view looks. If you like to use your own images then you can use ToggleButton and change its background: StateListDrawable example
This is how the native Switch view looks. If you like to use your own images then you can use ToggleButton and change its background: StateListDrawable example
Andris Active Member Licensed User Longtime User May 4, 2014 #10 Erel said: View attachment 23580 This class wraps the native Switch view using JavaObject. This view was added in Android 4+. You can either add the view with the designer as a CustomView (don't forget to set Custom Type field) or add it by code. See the attached example. Click to expand... Erel, in this code, Code: Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("1") sw.Initialize(Me, "sw") Activity.AddView(sw.Switch, 10dip, 10dip, 200dip, 50dip) sw.TextOff = "aaa" sw.TextOn = "bbb" End Sub these 2 lines Code: sw.TextOff = "aaa" sw.TextOn = "bbb" don't seem to do anything. I assume they are only to set text other than OFF and ON, but they don't work for me. Is this because the necessary sub in the class (setTextOn) is not being referenced correctly?
Erel said: View attachment 23580 This class wraps the native Switch view using JavaObject. This view was added in Android 4+. You can either add the view with the designer as a CustomView (don't forget to set Custom Type field) or add it by code. See the attached example. Click to expand... Erel, in this code, Code: Sub Activity_Create(FirstTime As Boolean) Activity.LoadLayout("1") sw.Initialize(Me, "sw") Activity.AddView(sw.Switch, 10dip, 10dip, 200dip, 50dip) sw.TextOff = "aaa" sw.TextOn = "bbb" End Sub these 2 lines Code: sw.TextOff = "aaa" sw.TextOn = "bbb" don't seem to do anything. I assume they are only to set text other than OFF and ON, but they don't work for me. Is this because the necessary sub in the class (setTextOn) is not being referenced correctly?
DonManfred Expert Licensed User Longtime User May 5, 2014 #11 Change android:targetSdkVersion="14"/> Click to expand... to android:targetSdkVersion="11"/> Click to expand... in Manifesteditor worked for me
Change android:targetSdkVersion="14"/> Click to expand... to android:targetSdkVersion="11"/> Click to expand... in Manifesteditor worked for me
Erel B4X founder Staff member Licensed User Longtime User May 5, 2014 #12 It should change the text (see the screenshot above). I've just tested it here on Android 4.4.2 and it works. Which version are you using?
It should change the text (see the screenshot above). I've just tested it here on Android 4.4.2 and it works. Which version are you using?
Andris Active Member Licensed User Longtime User May 5, 2014 #13 Erel said: It should change the text (see the screenshot above). I've just tested it here on Android 4.4.2 and it works. Which version are you using? Click to expand... My Galaxy S3 is running Android 4.3. I just tried changing the target SDK version in Manifest Editor to "13." It does then work as it should. But with "14" it does not. Last edited: May 5, 2014
Erel said: It should change the text (see the screenshot above). I've just tested it here on Android 4.4.2 and it works. Which version are you using? Click to expand... My Galaxy S3 is running Android 4.3. I just tried changing the target SDK version in Manifest Editor to "13." It does then work as it should. But with "14" it does not.
luke2012 Well-Known Member Licensed User Longtime User May 6, 2014 #14 If I understood well, this library is suitable from Android ICS to KitKat. So we have to catch the OS version and if it is before Android 4 we have to use other views intead of this, right ?
If I understood well, this library is suitable from Android ICS to KitKat. So we have to catch the OS version and if it is before Android 4 we have to use other views intead of this, right ?
B Brian Robinson Active Member Licensed User Longtime User Aug 3, 2014 #16 Is it possible to change the colour of the "on" state for this switch?
Erel B4X founder Staff member Licensed User Longtime User Aug 4, 2014 #17 You will need to create new images and use them instead (with StateListDrawable).
rleiman Well-Known Member Licensed User Longtime User Aug 16, 2014 #18 Hi, I tried it and the switch buttons show up but there is no text when I tap them. I used this in the manifest editor: Code: 'This code will be applied to the manifest file during compilation. 'You do not need to modify it in most cases. 'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136 AddManifestText( <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="11"/> <supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:anyDensity="true"/>) SetApplicationAttribute(android:icon, "@drawable/icon") SetApplicationAttribute(android:label, "$LABEL$") 'End of default text. Did I miss something else?
Hi, I tried it and the switch buttons show up but there is no text when I tap them. I used this in the manifest editor: Code: 'This code will be applied to the manifest file during compilation. 'You do not need to modify it in most cases. 'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136 AddManifestText( <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="11"/> <supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:anyDensity="true"/>) SetApplicationAttribute(android:icon, "@drawable/icon") SetApplicationAttribute(android:label, "$LABEL$") 'End of default text. Did I miss something else?
Erel B4X founder Staff member Licensed User Longtime User Aug 17, 2014 #19 Not even the ON and OFF text?
rleiman Well-Known Member Licensed User Longtime User Aug 17, 2014 #20 Hi Erel, No, the ON and OFF text is not showing up, only the switch view. I can tap them and they will toggle on and off but no text is showing up.
Hi Erel, No, the ON and OFF text is not showing up, only the switch view. I can tap them and they will toggle on and off but no text is showing up.