I have a sub like this. But the StateListDrawable not affect ... What is Wrong
B4X:
Sub AddButton
' Panel to host more than one buttons '
Dim p As Panel = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, 40dip, 40dip)
' First button'
Dim b As Button
b.Initialize("MyButton")
b.Text = "Button1"
' Colors for button state list'
' Enabled '
Dim gdEnable As GradientDrawable, clrEnable(2) As Int
clrEnable(0) = Colors.White
clrEnable(1) = Colors.LightGray
gdEnable.Initialize("TOP_BOTTOM", clrEnable)
' Disabled '
Dim gdDisable As GradientDrawable, clrDisable(2) As Int
clrDisable(0) = Colors.DarkGray
clrDisable(1) = Colors.LightGray
gdDisable.Initialize("TOP_BOTTOM", clrDisable)
'Pressed'
Dim gdPressed As GradientDrawable, clrPressed(2) As Int
clrPressed(0) = Colors.Green
clrPressed(1) = Colors.Yellow
gdPressed.Initialize("TOP_BOTTOM", clrPressed)
' Final StateListDrawable'
Dim std As StateListDrawable
std.Initialize
std.AddState2(Array As Int(std.State_enabled), gEnabled)
std.AddState2(Array As Int(std.State_Disabled), gDisable)
std.AddState2(Array As Int(std.State_Pressed), gPress)
std.AddCatchAllState(gEnabled)
' Add statelistdrawable to button.background '
b.Background = std
' This in sub Global '
Dim BtnB4x as B4XView
' Assign button to B4XView '
BtnB4x = b
BtnB4x.TextColor = Colors.Black
BtnB4x.TextSize = 16
BtnB4x.Visible = True
' Add B4XView button to panel '
p.AddView(BtnB4x,0,0,0,0)
BtnB4x.SetLayoutAnimated(0,0,100%x,100%y)
End sub
Last edited: