Sub Globals
Dim tb1, tb2 As ToggleButton
End Sub
Sub Activity_Create(FirstTime As Boolean)
' load the layout file
Activity.LoadLayout ("main")
' determine BitmapDrawables
Dim bdwChecked, bdwUnChecked As BitmapDrawable
' bitmap state
bdwChecked.Initialize (LoadBitmap(File.DirAssets, "btncharsizedown.bmp"))
bdwUnChecked.Initialize (LoadBitmap(File.DirAssets, "btncharsizeup.bmp"))
Dim sld1 As StateListDrawable
' initialize StateListDrawable
sld1.Initialize
' add states
sld1.AddState(sld1.State_Checked, bdwChecked)
sld1.AddState(sld1.State_Unchecked, bdwUnChecked)
' set background as state
tb1.Background = sld1
' determine ColorDrawables
Dim cdwChecked, cdwUnChecked As ColorDrawable
'colors state
cdwChecked.Initialize(Colors.Green, 10dip)
cdwUnChecked.Initialize(Colors.Red, 10dip)
Dim sld2 As StateListDrawable
' initialize StateListDrawable
sld2.Initialize
' add states
sld2.AddState(sld1.State_Checked, cdwChecked)
sld2.AddState(sld1.State_Unchecked, cdwUnChecked)
' set background as state
tb2.Background = sld2
' change the padding (margins) values
Dim refl As Reflector
refl.Target = tb2
Dim args(4) As Object
Dim types(4) As String
args(0) = 2dip ' left
args(1) = 2dip ' top
args(2) = 2dip ' right
args(3) = 2dip ' bottom
types(0) = "java.lang.int"
types(1) = "java.lang.int"
types(2) = "java.lang.int"
types(3) = "java.lang.int"
refl.RunMethod4("setPadding", args, types)
End Sub