B4A Library RMSwitch - https://github.com/RiccardoMoro/RMSwitch

A wrap for this Github project. You will need android-support-v4.jar and android-support-annotations.jar in your additional library folder.

Extract RMSwitchRes and copy the folder to be on the same folder level as that of the /Files and /Objects folders of the B4A project.

See the sample code for the event that is being raised in the B4A project for the slide switch being checked / not checked.

1.gif


Sample Code:
B4X:
#Region  Project Attributes
    #ApplicationLabel: RMSwitch
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#AdditionalRes: ..\RMSwitchRes

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private rms1 As RMSwitch
    Private rms2 As RMSwitch
    Private rms3 As RMSwitch
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
     Activity.LoadLayout("main")
    
     rms1.SwitchToggleCheckedDrawable = "male"
     rms1.SwitchToggleNotCheckedDrawable = "female"
     rms1.SwitchToggleNotCheckedColor = Colors.Gray
     rms1.SwitchToggleCheckedColor = Colors.Gray
     rms1.SwitchBkgCheckedColor = Colors.Green
     rms1.SwitchBkgNotCheckedColor = Colors.Red
     rms1.Checked = False
     rms1.ForceAspectRatio = False
    

     rms2.SwitchToggleCheckedDrawable = "happy"
     rms2.SwitchToggleNotCheckedDrawable = "sad"
     rms2.SwitchToggleNotCheckedColor = Colors.Red
     rms2.SwitchToggleCheckedColor = Colors.Blue
     rms2.SwitchBkgCheckedColor = Colors.Cyan
     rms2.SwitchBkgNotCheckedColor = Colors.Magenta
     rms2.Checked = False
     rms2.ForceAspectRatio = False    
    
    
     rms3.SwitchToggleCheckedDrawable = "confirm"
     rms3.SwitchToggleNotCheckedDrawable = "cancel"
     rms3.SwitchToggleNotCheckedColor = Colors.LightGray
     rms3.SwitchToggleCheckedColor = Colors.DarkGray
     rms3.SwitchBkgCheckedColor = Colors.Green
     rms3.SwitchBkgNotCheckedColor = Colors.DarkGray
     rms3.Checked = False
     rms3.ForceAspectRatio = False         
    
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub rms1_checked(isChecked As Boolean)
   
    Log("rms1 checked = " & isChecked)
   
End Sub

Sub rms2_checked(isChecked As Boolean)
   
    Log("rms2 checked = " & isChecked)
   
End Sub

Sub rms3_checked(isChecked As Boolean)
   
    Log("rms3 checked = " & isChecked)
   
End Sub

Take note of this in the above code:
B4X:
#AdditionalRes: ..\RMSwitchRes

Library:
RMSwitch
Author:
Github: Riccardo Moro, Wrapped by: Johan Schoeman
Version: 1
  • RMSwitch
    Events:
    • checked (isChecked As Boolean)
    Fields:
    • ba As BA
    Methods:
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    • toggle
    Properties:
    • Background As Drawable
    • Checked As Boolean [write only]
    • Color As Int [write only]
    • Enabled As Boolean
    • ForceAspectRatio As Boolean [write only]
    • Height As Int
    • Left As Int
    • Parent As Object [read only]
    • SwitchBkgCheckedColor As Int [write only]
    • SwitchBkgNotCheckedColor As Int [write only]
    • SwitchToggleCheckedColor As Int [write only]
    • SwitchToggleCheckedDrawable As String [write only]
    • SwitchToggleNotCheckedColor As Int [write only]
    • SwitchToggleNotCheckedDrawable As String [write only]
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int
 

Attachments

  • RMSwitchLibFiles.zip
    15.1 KB · Views: 336
  • b4aRMSwitch.zip
    12.7 KB · Views: 306
  • RMSwitchRes.zip
    6.9 KB · Views: 297
  • TheJavaCode.zip
    8.4 KB · Views: 308
Top