Android Question EditText Default Color

tomoshea

Member
Licensed User
Longtime User
Hi Erel,
I have an Edittext view where the background color changes based on a calculation.
It can change from Default to Red and vice versa.
Is it possible to change the background to the default so that the border reappears?
In other words how do I change it back to default with the border in code?
Thanks,
Kind Regards
Tom
 

Mahares

Expert
Licensed User
Longtime User
You can use the tag property of the edittext to store the original background color. See example below:
B4X:
Dim btn As Button
Dim et As EditText
 
btn.initialize("btn")
btn.Text="Click me"
Activity.AddView(btn,0,0,20%x,75dip)
et.Initialize("et")
et.Typeface=Typeface.DEFAULT_BOLD
et.TextSize= 18
et.TextColor=Colors.Yellow
et.Tag=et.Background 'Store original color in tag in activity_Create
et.InputType=et.INPUT_TYPE_DECIMAL_NUMBERS
Activity.AddView(et,40%x,0,20%x,75dip)
 
 
 
Sub btn_Click
If IsNumber(et.Text) AND et.Text > 10Then
  et.Color=Colors.Red
Else
  et.background=et.Tag
EndIf
End Sub
Please note that when you only ask one person to help you in the forum, you are excluding over 40000 more that may be able to help.
 
Upvote 0

stu14t

Active Member
Licensed User
Longtime User
I think I'm missing something here. I get an error if I use the code above.

I've tried to implement this but the Edittext.Bacground is expecting an integer and not a color.drawable. What have I done wrong?
 
Upvote 0

stu14t

Active Member
Licensed User
Longtime User
My fault. I was trying to set Color to Background instead of background to background
 
Upvote 0
Top