### ImageView ToggleButton

Example creating an ImageView as a ToggleButton.
Add Images
Copy two images e.g. switch_on.png and switch_off.png to the project files folder (dirassets).
Hint: Nice images to be found in http://findicons.com/search/switch-off or /switch_on
Add the two files to the B4J IDE Files Manager.
Create ImageView in Layout
Use the B4J Visual Designer.
In the layout file, add a new View ImageView.
Properties:
Name: ivOutdoorLightSwitch
Size f.e. 30 x 50.
Bacjground Properties: Bitmapdrawble with initial image switch_on.png.
This requires to add the two images to the layout (tab files, add files).
Generate the image into the class (main or any other class) and in addition a global flag to capture the state.
`Sub Class_Globals
Private ivOutdoorLightSwitch As ImageView
Private stateOutdoorlight As Boolean = False
...
Define the code to handle the Mouse Click on the Image ivOutdoorLightSwitch
`Sub ivOutdoorLightSwitch_MouseClicked (EventData As MouseEvent)
stateOutdoorlight = Not(stateOutdoorlight)
If stateOutdoorlight Then
ivOutdoorLightSwitch.SetImage(fx.LoadImage(File.DirAssets, "Switch_off.png"))
Else
ivOutdoorLightSwitch.SetImage(fx.LoadImage(File.DirAssets, "Switch_on.png"))
End If
Log($"Outdoor Light state: ${stateOutdoorlight}"$)
End Sub`
`

Changed: , Category: Image and ImageView, File: T6C199M1465.htm, ID: 1465