Skip to content Skip to sidebar Skip to footer

Textinput Layout Turns Editext Into Red On Setting Error

I have a layout, whenever i press submit button and set error on text input layout it turns the editText into red but i hadn't set any color on editText on set error. Basically

Solution 1:

You have to setError() not to TextInputLayout but to EditText inside TextInputLayout.

XML : here I assigned id for EditText inside TextInputLayout;

<android.support.design.widget.TextInputLayout
    style="@style/textInputLayout"
    android:id="@+id/fs_ti_email">

    <EditText

        android:id="@+id/edit_text_email" <!-- here your id-->
        style="@style/edittext"
        android:tag="@string/str_email"
        android:hint="@string/str_email"/>
</android.support.design.widget.TextInputLayout>

Java: here I find EditText by ID and assign setError() to it.

EditText email;

        //your code here...
        ...
  @OverridepublicvoidonClick(View v) {
    switch (v.getId())
    {
        case R.id.fs_bt_submit:
        {
            email.setError("Not a valid email address!");
        }break;
    }
  }

Post a Comment for "Textinput Layout Turns Editext Into Red On Setting Error"