-1

Is it possible to disable the hint whenever setting the error on the text input layout. I tried passing in null and an empty string, but at that point it won't make the lines red.

I also pass in a string with a space, but if i do that then the hint still takes up the space under the edittext's underline.

I tried to change the underline color to red but it seems to take a lot of work to to that. I'm currently on API 19.

So is it possible to just disable the hint?

Thanks

huey77
  • 643
  • 1
  • 9
  • 24
  • Check [this question](https://stackoverflow.com/questions/35423569/disable-remove-floating-label-hint-text-in-textinputlayout-xml) and the accepted answer. It might help you. – deluxe1 Mar 23 '18 at 17:16
  • That is with regular hints, the ones that float on top. Thanks though – huey77 Mar 23 '18 at 17:17

2 Answers2

1

So I don't think it is possible to disable the hint for the error (I could possibly be very wrong). The best way to handle this is to just change the color of the line in the editText by using setSupportBackgroundTintList or setBackgroundTintList.

A few key things.

1) If you are on sdkVersion 23 or higher then you can use the regular editText and the setBackgroundTintList method.

2) If you are between then 23-19, I think you can use it on lower sdkVersions as well. You have to use the Appcompat EditText in your layout.

3) Using setSupportBackgroundTintList will show as an error, but that is because there is a bug with the support library.You can just suppress the lint error in the method/place you are using it.

Here are some code snippets. I hope this helps anyone who is just looking to change the color of the line in an editText.

AppCompatEditText in my layout.

<android.support.design.widget.TextInputLayout
        android:id="@+id/login_user_password_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:hint="@string/login_hint_password"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@id/login_user_email_layout"
        app:layout_constraintBottom_toTopOf="@id/error_text"
        app:layout_constraintRight_toRightOf="parent">

        <android.support.v7.widget.AppCompatEditText
            android:id="@+id/login_user_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword"
            android:imeOptions="actionDone"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"/>

</android.support.design.widget.TextInputLayout>

Method I set the underline color in.

@SuppressLint("RestrictedApi")
private void setEditTextFields(){
    if(errorLoginIn){
        errorLoginIn = false;
        binding.errorText.setVisibility(View.VISIBLE);
        binding.loginUserEmail.setSupportBackgroundTintList(getResources().getColorStateList(R.color.colorError));
        binding.loginUserPassword.setSupportBackgroundTintList(getResources().getColorStateList(R.color.colorError));
    }else{
        binding.errorText.setVisibility(View.INVISIBLE);
        binding.loginUserEmail.setSupportBackgroundTintList(getResources().getColorStateList(R.color.primaryColor));
        binding.loginUserPassword.setSupportBackgroundTintList(getResources().getColorStateList(R.color.primaryColor));
    }
}

binding is the layout since I'm using data binding.

Hope this helps someone.

huey77
  • 643
  • 1
  • 9
  • 24
1

Yes, it is possible to just disable the error text and show underlined red line. Despite @huey77 answer might help, but it is complicated and needs to control states manually

My solution is easy and simple, just to use errorTextAppearance with 0dp:

 <style name="TextError" parent="TextAppearance.AppCompat">
    <item name="android:textSize">0dp</item>
    <item name="android:textColor">?colorError</item>
</style>

<style name="TextInputLayout" parent="Widget.Design.TextInputLayout">
    <item name="errorTextAppearance">@style/TextError</item>
</style>

in your app theme:

<item name="textInputStyle">@style/TextInputLayout</item>
Beloo
  • 9,723
  • 7
  • 40
  • 71