Handling Errors
suggest changeYou can use the TextInputLayout to display error messages according to the material design guidelines using the setError and setErrorEnabled methods.
In order to show the error below the EditText use:
TextInputLayout til = (TextInputLayout) findViewById(R.id.username);
til.setErrorEnabled(true);
til.setError("You need to enter a name");
To enable the error in the TextInputLayout, you can either use app:errorEnabled="true" in XML or til.setErrorEnabled(true); as shown above.
You will obtain:
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents