Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

InputTextLayout setError() method in Android not working

I have designed a customised InputTextLayout which contains a custom Edittext.This custom Edittext extends the "AppCompatEdittext". Also my MainActivity extends AppCompatActivity. But still I am not able to show the error messages using TextInputLayout. Below are my code snippets from various files.

main.xml

<android.support.design.widget.TextInputLayout
            android:id="@+id/last_name_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/first_name_layout"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"
            android:layout_marginTop="12dp"
            android:background="@drawable/grey_button_normal"
            android:hint="Last name"
            android:minHeight="48dp"
            android:paddingTop="3dp"
            android:theme="@style/TextLabel">

            <com.feebite.widgets.StyleableEditText
                android:id="@+id/lastname_edittext"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_gravity="center_vertical"
                android:background="@android:color/transparent"
                android:gravity="center_vertical"
                android:minHeight="48dp"
                android:nextFocusDown="@+id/email_edittext"
                android:paddingBottom="10dp"
                android:paddingLeft="15dp"
                android:singleLine="true"
                android:textColor="@color/darkish_grey"
                android:textColorHint="@color/darkish_grey"
                android:textCursorDrawable="@null"
                android:textSize="18sp" />

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

MainActivity.java

mLastNameLayout = (TextInputLayout) findViewById(R.id.last_name_layout);
 mLastNameLayout.setHint("Last name");
mLastNameLayout.setErrorEnabled(true);

Custom theme from styles.xml

<style name="TextLabel" parent="TextAppearance.AppCompat">
        <!-- Hint color and label color in FALSE state -->
        <item name="android:textColorHint">@color/darkish_grey</item>
        <!-- Label color in TRUE state and bar color FALSE and TRUE State -->
        <item name="colorAccent">@color/darkish_grey</item>
        <item name="colorControlNormal">@color/darkish_grey</item>
        <item name="colorControlActivated">@color/dark_pink</item>
    </style>

And the error displayed.

FATAL EXCEPTION: main
                                                             Process: com.feebite, PID: 18611
                                                             java.lang.RuntimeException: Unable to start activity ComponentInfo{com.feebite/com.feebite.userRegisteration.SignUpActivity}: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 24: TypedValue{t=0x3/d=0x45a "res/color/secondary_text_material_light.xml" a=1 r=0x106011e}
                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                 at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                 at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                 at android.os.Looper.loop(Looper.java:148)
                                                                 at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                 at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:117)
                                                              Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 24: TypedValue{t=0x3/d=0x45a "res/color/secondary_text_material_light.xml" a=1 r=0x106011e}
                                                                 at android.content.res.TypedArray.getColor(TypedArray.java:447)
                                                                 at android.content.res.XResources$XTypedArray.getColor(XResources.java:1033)
                                                                 at android.widget.TextView.<init>(TextView.java:738)
                                                                 at android.widget.TextView.<init>(TextView.java:671)
                                                                 at android.widget.TextView.<init>(TextView.java:667)
                                                                 at android.widget.TextView.<init>(TextView.java:663)
                                                                 at android.support.design.widget.TextInputLayout.setErrorEnabled(TextInputLayout.java:380)
                                                                 at com.feebite.userRegisteration.SignUpActivity.onCreate(SignUpActivity.java:59)
                                                                 at android.app.Activity.performCreate(Activity.java:6251)
                                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                 at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                 at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                 at android.os.Looper.loop(Looper.java:148) 
                                                                 at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                 at java.lang.reflect.Method.invoke(Native Method) 
                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                                 at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:117) 
like image 225
AndroidMech Avatar asked Feb 10 '16 11:02

AndroidMech


People also ask

How do I remove TextInputLayout error?

Now you can simply do input. setError(..) for new error and input. setErrorEnabled(false) to remove it.

How do I show error on TextInputLayout?

You can use the TextInputLayout to display error messages according to the material design guidelines using the setError and setErrorEnabled methods. In order to show the error below the EditText use: TextInputLayout til = (TextInputLayout) findViewById(R. id.


2 Answers

Try to set the following attributes too:

<item name="android:textColorHighlight">@color/Your color</item>
<item name="android:textColorLink">@color/Your color</item>
like image 144
Dávid Kisida Avatar answered Nov 09 '22 10:11

Dávid Kisida


Had exactly the same problem and none of the answers solved. What really worked was removing this: parent="TextAppearance.AppCompat"

like image 41
GuilhE Avatar answered Nov 09 '22 12:11

GuilhE