Android Question [SOLVED] Change color to edge to button at runtime

desof

Well-Known Member
Licensed User
Longtime User
I have a button that at the time of design applies the property BorderWidth = 1 and BorderColor = FFF9F9F9.
This is perfect until at run time I apply color to the bottom of the button!

B4X:
Dim AC As AppCompat
Button1.Color= AC.GetThemeAttribute("colorAccent")

Is it possible to prevent this from happening?
or
Is it possible to set the edge property at run time?
 

davidvidasoft

Member
Licensed User
It may be because you are replacing the previously set properties. Try this:
B4X:
    Dim AC As AppCompat
  
    Dim sldButton1 As StateListDrawable
    Dim cdButton1 As ColorDrawable
  
    sldButton1.Initialize
    cdButton1.Initialize2(AC.GetThemeAttribute("colorAccent"), 0dip, 1dip, 0xFFF9F9F9) ' 0xFFF9F9F9: not sure if it's the correct syntax but you can change it with Color.RGB(...)
  
    sldButton1.AddState(sldButton1.State_Enabled, cdButton1) ' State_Enabled
  
    cdButton1.Background = sldButton1
I haven't tested it but it should work
 
Upvote 0

desof

Well-Known Member
Licensed User
Longtime User
GREAT FRIEND !!!!
I did not know this method of implementation!
A huge hug from Argentina!
 
Upvote 0
Top