Android Question A strange phenomenon?

sailorxft

New Member
When you use the following code, all text input boxes are narrowed when you click the text box. Just like this, just...

long.png
short.png

B4X:
    Private gdwGradient As GradientDrawable
    Private cols(2) As Int
    Private cdwColor As ColorDrawable

    cols(0) = Colors.ARGB(255,100,255,255)
    cols(1) = Colors.Transparent
    gdwGradient.Initialize("TOP_BOTTOM", cols)
    gdwGradient.CornerRadius = 5

    spnUnittype.Background = gdwGradient
    cdwColor.Initialize(Colors.ARGB(255,255,255,255), 0dip)
    edtInput.Background = cdwColor

    edtOutput.Background = cdwColor
    spnInput.Background = cdwColor
    spnOutput.Background = cdwColor
    spnUnittype.DropdownBackgroundColor = Colors.ARGB(255,200,255,255)
    spnInput.DropdownBackgroundColor = Colors.ARGB(255,255,255,200)
    spnOutput.DropdownBackgroundColor = Colors.ARGB(255,255,255,200)
 

sailorxft

New Member
The problem is solved. The codes that changes the background can not be just placed in "Activity_Create", and should added to "edtInput_FocusChanged". Just like this:

B4X:
Sub edtInput_FocusChanged (HasFocus As Boolean)
    cdwColor.Initialize(Colors.ARGB(255,255,255,255), 0dip)
    edtInput.Background = cdwColor
    edtOutput.Background = cdwColor
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Just like this
this is the wrong solution.
As mentioned my Erel each drawable should br s new instance of the drawable

B4X:
Private cdwColor As ColorDrawable
cdwColor.Initialize(Colors.ARGB(255,255,255,255), 0dip)
edtInput.Background = cdwColor

If you now need another ColorDrawable then create a new one....
It can be the same name.... The dirreference is that i DIM a new Instance and initialize this instance instead of reusing the old Object.
B4X:
Private cdwColor As ColorDrawable
cdwColor.Initialize(Colors.ARGB(255,255,255,255), 0dip)
edtOutput.Background = cdwColor

If you now need another ColorDrawable then create a new one.... [and so on]
 
Last edited:
Upvote 0
Top