Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SetError produces exception with custom style in TextInputLayout

I'm using an Edittext inside of a TextInputLayout using a custom style so that I can change the hint color. If I use the EditText without setting the style, the setError method works fine, but with my style set the next exception is thrown:

java.lang.UnsupportedOperationException: Failed to resolve attribute at index 24: TypedValue{t=0x3/d=0x2b5 "res/color/secondary_text_material_dark.xml" a=1 r=0x1060166}
                                                                             at android.content.res.TypedArray.getColor(TypedArray.java:447)
                                                                             at android.widget.TextView.<init>(TextView.java:745)
                                                                             at android.widget.TextView.<init>(TextView.java:678)
                                                                             at android.widget.TextView.<init>(TextView.java:674)
                                                                             at android.widget.TextView.<init>(TextView.java:670)
                                                                             at android.support.design.widget.TextInputLayout.setErrorEnabled(TextInputLayout.java:380)
                                                                             at android.support.design.widget.TextInputLayout.setError(TextInputLayout.java:425)
                                                                             at com.wallakoala.wallakoala.Activities.SignUpUI.validateEmail(SignUpUI.java:50)
                                                                             at com.wallakoala.wallakoala.Activities.SignUpUI.access$100(SignUpUI.java:21)
                                                                             at com.wallakoala.wallakoala.Activities.SignUpUI$MyTextWatcher.afterTextChanged(SignUpUI.java:103)
                                                                             at android.widget.TextView.sendAfterTextChanged(TextView.java:8017)
                                                                             at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:10182)
                                                                             at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:1043)
                                                                             at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:560)
                                                                             at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:492)
                                                                             at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:34)
                                                                             at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:685)
                                                                             at android.view.inputmethod.BaseInputConnection.setComposingText(BaseInputConnection.java:445)
                                                                             at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:340)
                                                                             at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:78)
                                                                             at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                             at android.os.Looper.loop(Looper.java:224)
                                                                             at android.app.ActivityThread.main(ActivityThread.java:5526)
                                                                             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)

This is the XML of the EditText

<android.support.design.widget.TextInputLayout
        android:id="@+id/email_input_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginRight="34dp"
        android:layout_marginLeft="34dp"
        android:layout_marginTop="12dp"
        android:theme="@style/TextLabel">

        <EditText
            android:id="@+id/email_edittext"
            android:inputType="textEmailAddress"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:textColor="@color/colorText"
            android:textColorHint="@color/colorMediumText"
            android:hint="@string/email_hint"
            android:nextFocusUp="@id/email_edittext"
            android:nextFocusLeft="@id/email_edittext"/>

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

This is the style defined in styles.xml.

<style name="TextLabel" parent="TextAppearance.AppCompat">
    <item name="android:textColorHint">@color/colorLightText</item>
    <item name="android:textSize">14dp</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="colorControlNormal">@color/colorMediumText</item>
    <item name="colorControlActivated">@color/colorAccent</item>
</style>

And this is the line that produces the error:

emailInputLayout.setError("Incorrect email");

Any idea of what's happening?

Thanks in advance,

like image 434
Dani M Avatar asked Jun 12 '16 11:06

Dani M


People also ask

How do I remove TextInputLayout error?

setError(..) for new error and input. setErrorEnabled(false) to remove it.

What is the use of TextInputLayout in Android?

The primary use of a TextInputLayout is to act as a wrapper for EditText(or its descendant) and enable floating hint animations. Rule of Thumb : TextInputLayout should wrap TextInputEditText instead of the normal EditText.

What is text view?

TextView is the user interface which displays the text message on the screen to the user. It is based on the layout size, style, and color, etc. TextView is used to set and display the text according to our specifications.


1 Answers

I found the error, these attributes have to be in the style:

<item name="android:textColorHighlight">@color/COLOR</item>
<item name="android:textColorLink">@color/COLOR</item>
like image 109
Dani M Avatar answered Oct 20 '22 01:10

Dani M