Android Question Change border color button in code

bluedude

Well-Known Member
Licensed User
Hi,

I have set the border color of a button in the designer but now I need to change it dynamically in code, how to do that?
 

bluedude

Well-Known Member
Licensed User
Mm, does not work as expected. When pressing the button there is no pressed default effect.
 

bluedude

Well-Known Member
Licensed User
I have done that but still some issues with pressed. See below:

Dim btnThemeBlue,btnThemeWhite,btnThemeWhiteClicked As ColorDrawable
Dim sldBlue,sldWhite As StateListDrawable

sldBlue.Initialize
sldWhite.Initialize

btnThemeBlue.Initialize2(Colors.RGB (23, 126, 251),5dip,1dip,Colors.RGB (23, 126, 251))
btnThemeWhite.Initialize2(Colors.White,5dip,1dip,Colors.RGB (23, 126, 251))
btnThemeWhiteClicked.Initialize2(Colors.RGB (169, 169, 169),5dip,1dip,Colors.RGB (23, 126, 251))

sldBlue.AddState (sldBlue.State_Enabled,btnThemeBlue)
sldBlue.AddState (sldBlue.State_Pressed ,btnThemeWhiteClicked)

sldWhite.AddState (sldWhite.State_Enabled,btnThemeWhite)
sldWhite.AddState (sldWhite.State_Pressed ,btnThemeWhiteClicked)

btnTest.Background = sldWhite
 

klaus

Expert
Licensed User
Invert Enabled and Pressed:
sldWhite.AddState (sldWhite.State_Pressed ,btnThemeWhiteClicked)
sldWhite.AddState (sldWhite.State_Enabled,btnThemeWhite)
 
Top