I need an EditText
that looks like this onError:
calling onError looks like this instead :
Note: the app is running on SDK 19 (4.4.2)
min SDK is 1
Is there a method similar to setError that does this automatically, or do I have to write the code for it ?
Thank you
There's no need to use a third-party library since Google introduced the
TextInputLayout
as part of thedesign-support-library
.Following a basic example:
Layout
Note: By setting
app:errorEnabled="true"
as an attribute of theTextInputLayout
it won't change it's size once an error is displayed - so it basically blocks the space.Code
In order to show the Error below the
EditText
you simply need to call#setError
on theTextInputLayout
(NOT on the childEditText
):Result
To hide the error and reset the tint simply call
til.setError(null)
.Note
In order to use the
TextInputLayout
you have to add the following to yourbuild.gradle
dependencies:Setting a custom color
By default the line of the
EditText
will be red. If you need to display a different color you can use the following code as soon as you callsetError
.To clear it simply call the
clearColorFilter
function, like this: