Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextInputLayout set error without message?

Is is possible to set error on Text Input Layout without showing any error message (i'm already doing it in another place)?.

textinputlayout.setError("");

won't work unfortunately.

What i basically need is the textInputLayout to change its line color to red, but i need to do it programmatically. Thank you

like image 914
oxcened Avatar asked Mar 12 '17 21:03

oxcened


People also ask

How do I remove the default padding in TextInputLayout?

You can just set the start and end padding on the inner EditText to 0dp. Here's a screenshot with Show Layout Bounds turned on so you can see that the hints go all the way to the edge of the view. Save this answer.


2 Answers

The error text (even " ") will take/reserve some height in the TextInputLayout. If you also want to get rid of it then

<com.google.android.material.textfield.TextInputLayout      
    ...
    app:errorTextAppearance="@style/MyZeroSizeTextAppearance"
    ...
    >

Text appearance:

<style name="MyZeroSizeTextAppearance">
    <item name="android:textSize">0sp</item>
</style>

and then

textinputlayout.setError(" ");
like image 159
Max Diland Avatar answered Oct 16 '22 06:10

Max Diland


Hope it's not too late, but the code behind setError is:

if (!mErrorEnabled) {
   if (TextUtils.isEmpty(error)) {
      // If error isn't enabled, and the error is empty, just return
      return;
   }
}

this means a simple workaround would be:

textinputlayout.setError(" ");

please be advised, that this will make TextView with error message visible - so it will make TextInputLayout higher even if it will be empty

since this passes the not-so-well-thought-out case of handling an empty error message request.

like image 36
Simon Avatar answered Oct 16 '22 06:10

Simon