Subname: CreateStateListDrawableView
Description: This is a great sub to make custom buttons (especially pictures). You only need to set one bitmap, and this sub will create the pressed state automatically with a highlighted color to show the pressed state.
Requirements: This requires the view(cmd) be already added to an activity/panel.
Tags: UI, StateListDrawable, Button, Highlight
Description: This is a great sub to make custom buttons (especially pictures). You only need to set one bitmap, and this sub will create the pressed state automatically with a highlighted color to show the pressed state.
Requirements: This requires the view(cmd) be already added to an activity/panel.
B4X:
Sub CreateStateListDrawable(bmp As Bitmap,cmd As View )
Dim C As Canvas
Dim r1 As Rect
Dim r2 As Rect
Dim sld As StateListDrawable
Dim Padding As Int
Padding = 0
'Create a temporary button and draw on it
C.Initialize(cmd)
r1.Initialize(0,0,cmd.Width,cmd.Height)
r2.Initialize(Padding,Padding,cmd.Width-Padding,cmd.height-Padding)
sld.Initialize
C.DrawColor(Colors.RGB(58, 162, 203))
C.DrawBitmap(bmp,Null,r2)
cmd.Invalidate
sld.AddState(sld.State_Pressed,cmd.Background)
Dim bmd As BitmapDrawable
bmd.Initialize(bmp)
sld.AddState(sld.State_Enabled, bmd)
cmd.Background = sld
End Sub
Tags: UI, StateListDrawable, Button, Highlight
Last edited: