Android Question button size became larger after I set its border

Hello everyone,

I want to implement a button effect: when the button is clicked, it shows a border. When the button is clicked again, it returns to its borderless state.

During the implementation, I found that after the border appears, the button's size increases. Additionally, after removing the border, the button does not return to its original size.

I would like to ask, is this the intended design for the button? Or is there something I might have done wrong?
 
Solution
This is the expected result. In this case the button will look with the same size in all states. It will indeed look different than standard buttons.

One possible option is to change the appearance of all buttons.
Hi, Erel, I tried to use StateListDrawable, but the button size is still larger than expected.

my code is like this:
B4X:
'Set the style of a button
'chosen=True: style2 when button is chosen。 || chosen=False: style1 when button is not chosen
private Sub SetButtonStyle(button As B4XView, chosen As Boolean)
    Private sld As StateListDrawable
    
    Private cd1,cd2 As ColorDrawable
    cd1.Initialize2(Colors.Gray,0,0,Colors.Transparent) 'style1
    cd2.Initialize2(Colors.White,0,1dip,Colors.Black)  'style2
    
    If chosen=True Then
        sld.Initialize
        sld.AddState(sld.State_Enabled,cd2)
        button.As(Button).Background=sld
    Else
        sld.Initialize
        sld.AddState(sld.State_Enabled,cd1)
        button.As(Button).Background=sld
        
    End If

End Sub
 

Attachments

  • 0821_1.jpg
    84.9 KB · Views: 42
Upvote 0
This is the expected result. In this case the button will look with the same size in all states. It will indeed look different than standard buttons.

One possible option is to change the appearance of all buttons.
Following your suggestion, I changed the initial appearance of all buttons and modified their layout. Now the buttons look much better. Thanks!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…