Android Question Issues with EditText and Background

Christian García S.

Active Member
Licensed User
Hello, maybe you can help me.

I have two edittext with this characteristics:

upload_2019-9-20_17-44-33.png


And I put background to these with:

B4X:
Dim cd As ColorDrawable
cd.Initialize2(Colors.White,8dip,1,0xFF808080)
   
txtCodigo.Background = cd
txtAdicional.Background = cd

All works fine:

upload_2019-9-20_17-48-24.png


When I clicked on a text, the right edge was lost

upload_2019-9-20_17-49-35.png



I have tried to change the layout of the images, their alignment, but the same behavior is always repeated, I have changed the size of the text and I always have the same results.

Thanks

Christian.
 

Sagenut

Expert
Licensed User
Longtime User
Do not use the same ColorDrawable for different items.
That generate that behaviour.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Good that it helped.
I suggest You to create a sub like this
B4X:
Sub background (backcolor As Int, radius As Int, borderwidth As Int, bordercolor As Int) As ColorDrawable
    Dim cd As ColorDrawable
    cd.Initialize2(backcolor,radius,borderwidth,bordercolor)
    Return cd
End Sub
Then every time You need to set a ColorDrawable to a view just type
B4X:
MyView.Background = background(Colors.White,8dip,1,0xFF808080)
Of course You can pass different parameters as needed at every call.
In this way You don't need to create a single variable for every view.
 
Upvote 0
Top