Android Question [SOLVED] StateListDrawable on 2 buttons

manuel_g

Member
Licensed User
Hi!
I'm using StateListDrawable on 2 buttons and when I press Button1 the Button2 changes to pressed, too. But, if I press Button2 the Button1 works ok.
Also, the button1 doesn't show with the correct width, it seems like the Button2 forces its width.

This is the code:
B4X:
Dim benabled, bpressed, bdisabled As ColorDrawable
    benabled.Initialize(Colors.red, 100dip)
    bpressed.Initialize(Colors.green, 100dip)
    bdisabled.Initialize(Colors.blue, 100dip)
    
Dim sld As StateListDrawable
    sld.Initialize
    sld.AddState(sld.State_Disabled,bdisabled)
    sld.AddState(sld.State_Pressed,bpressed)
    sld.AddState(sld.State_Enabled,benabled)
    sld.AddCatchAllState(benabled)
    
Button2.Background = sld
Button1.Background = sld

If I switch this:
Button1.Background = sld
Button2.Background = sld
when I press the EditText the Button1 changes its width.

Project is attached.
Thank you so much
 

Attachments

  • statelistdrawable.zip
    11.3 KB · Views: 249

DonManfred

Expert
Licensed User
Longtime User
Do not reuse a drawable.
Create a new crawable for each button.
 
Upvote 0
Top