Sub Process_Globals
Dim ColBackground As Int : ColBackground = Colors.RGB(255,230,130)
Dim ColSelected As Int : ColSelected = Colors.RGB(255,200,200)
End Sub
Sub Globals
Dim SelectedLabel, Label1, Label2, Label3 As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
End Sub
Sub Activity_Resume
' initializes the backgrounds
SetBackground(Label2)
SetBackground(Label3)
SetSelected(Label1)
End Sub
Sub Label_Click
SetBackground(SelectedLabel)
Dim lbl As Label
lbl = Sender
SetSelected(lbl)
End Sub
Sub SetBackground(lbl As Label)
' draws the background
Dim cvs As Canvas
Dim bmp As Bitmap
Dim bmd As BitmapDrawable
Dim rc As Rect
rc.Initialize(0, 0, lbl.Width, lbl.Height)
bmp.InitializeMutable(lbl.Width, lbl.Height)
bmd.Initialize(bmp)
cvs.Initialize2(bmp)
cvs.DrawRect(rc, ColBackground, True, 1)
lbl.Background = bmd
End Sub
Sub SetSelected(lbl As Label)
' draws the background
Dim cvs As Canvas
Dim bmp As Bitmap
Dim bmd As BitmapDrawable
Dim rc As Rect
rc.Initialize(0, 0, lbl.Width, lbl.Height)
bmp.InitializeMutable(lbl.Width, lbl.Height)
bmd.Initialize(bmp)
cvs.Initialize2(bmp)
cvs.DrawRect(rc, ColBackground, True, 1)
' draws text background with the select color
Dim xt, x1, x2 As Int
xt = cvs.MeasureStringWidth(lbl.Text, lbl.Typeface, lbl.TextSize) + 4dip
x1 = (lbl.Width - xt) / 2
x2 = x1 + xt
rc.Initialize(x1, 0, x2, lbl.Height)
cvs.DrawRect(rc, ColSelected, True, 1)
lbl.Background = bmd
SelectedLabel = lbl
End Sub