Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set border color for EditText for validation error

I am applying validation on my login form in android application.

If any EditText fields is null (empty) then I want to set Red color border for that EditText.

If user fill any data in this Red bordered EditText then it should turn to default EditText.

How can I implement this?

like image 526
Manoj Agarwal Avatar asked May 25 '12 07:05

Manoj Agarwal


1 Answers

Just a tip:

Why don't you use EditText.setError("Oh, this is wrong");

Relevant documentation says:

Sets the right-hand compound drawable of the TextView to the "error" icon and sets an error message that will be displayed in a popup when the TextView has focus. The icon and error message will be reset to null when any key events cause changes to the TextView's text. If the error is null, the error message and icon will be cleared.

Another blog entry covering this topic.

like image 72
Adil Soomro Avatar answered Oct 22 '22 22:10

Adil Soomro