0

I am applying the setError() method on TextInputLayout and TextInputEditText but I am getting this error,

What I am trying to achieve is the error tooltip.I am in no mood of using any third party libraries to achieve this.\

Here is what I tried and none of these worked,

Error in TextInputLayout dont show again even call setErrorEnabled(true)

TextInputLayout setErrorEnabled doesn't create new TextView object

TextInputLayout.setError() leaves empty space after clearing the error

TextInputLayout not showing error message after clearing

setError for TextInputLayout showing Error

TextInputLayout error after enter value into edittext

textinputlayout errorenabled and showing errors

textinputlayout errorenabled and showing errors

TextInputLayout's errorview is not removed when removing error message

Gradle

compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
    compile 'com.android.support:support-v4:25.3.1'

Error Stacktrace,

Process: com.example.demo, PID: 31847
                                                                       java.lang.UnsupportedOperationException: Failed to resolve attribute at index 24: TypedValue{t=0x3/d=0x1ec "res/color/secondary_text_material_dark.xml" a=1 r=0x1060120}
                                                                           at android.content.res.TypedArray.getColor(TypedArray.java:449)
                                                                           at android.widget.TextView.<init>(TextView.java:741)
                                                                           at android.widget.TextView.<init>(TextView.java:674)
                                                                           at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:62)
                                                                           at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:58)
                                                                           at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:54)
                                                                           at android.support.design.widget.TextInputLayout.setErrorEnabled(TextInputLayout.java:602)
                                                                           at com.example.demo.DemoActivity.canLogin(DemoActivity.java:163)
                                                                           at com.example.demo.DemoActivity.access$000(DemoActivity.java:24)
                                                                           at com.example.demo.DemoActivity$1.onClick(DemoActivity.java:54)
                                                                           at android.view.View.performClick(View.java:5207)
                                                                           at android.view.View$PerformClick.run(View.java:21177)
                                                                           at android.os.Handler.handleCallback(Handler.java:742)
                                                                           at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                           at android.os.Looper.loop(Looper.java:154)
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5527)
                                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)

Here is the XML

<android.support.design.widget.TextInputLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:hint="UserName"
        android:theme="@style/txtIptLayout"
       android:layout_marginTop="10dp"
       app:backgroundTint="@color/white"
        android:id="@+id/tilUsername"
       app:errorTextAppearance="@style/Theme.AppCompat"
       >
     <android.support.design.widget.TextInputEditText
         style="@style/txtEditTxtLayout"
         app:backgroundTint="@color/white"
         android:id="@+id/etUserName"
         android:maxLines="1"
         android:inputType="text"

         />

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

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Password"
        android:theme="@style/txtIptLayout"
        app:passwordToggleEnabled="true"
        app:passwordToggleDrawable="@drawable/ic_widget_icon_txtiptlayout"
        app:passwordToggleTint="@color/white"
        android:layout_marginTop="10dp"
        app:backgroundTint="@color/white"
       app:errorTextAppearance="@style/Theme.AppCompat"
        android:id="@+id/tilPassword"
        >
        <android.support.design.widget.TextInputEditText
           style="@style/txtEditTxtLayout"
            android:inputType="textPassword"
            android:id="@+id/etPassword"
            app:backgroundTint="@color/white"


            />

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

Here is what I am applying and this is where exactly the error is thrown,

tilPassword.setError("Password required");
                tilPassword.setErrorEnabled(true);
oldcode
  • 1,669
  • 3
  • 22
  • 41
  • Just FYI, `TextInputLayout`'s error text isn't an "error tooltip that hovers over the text box". It appears underneath the `EditText`. An `EditText`'s error is a tooltip, though. – Mike M. Oct 11 '17 at 07:55
  • @MikeM. Ok it also doesn't appear underneath. it does not display instead that error is thrown. So can it be rectified ? – oldcode Oct 11 '17 at 07:58

3 Answers3

0

Try this:

  tilPassword.getEditText().setError("Password required");
  tilPassword..setErrorEnabled(true);
jakir hussain
  • 316
  • 2
  • 18
0

Not sure how but removing the theme attribute in XML android:theme="@style/txtIptLayout" worked. The assumption would be that overriding the theme from XML will override the theme for the tooltip and hence the error.

oldcode
  • 1,669
  • 3
  • 22
  • 41
0

Well this happens, when you try to override the theme from XML, it will override the default functionalities as well. i have faced similar issue where i was creating a style parenting TextAppearance.AppCompat.

Replacing it with Theme.AppCompat resolved my issue.

Bilal
  • 1,034
  • 11
  • 23