我正在使用自定义样式在TextInputLayout内部使用Edittext,以便我可以更改提示颜色。如果我在不设置样式的情况下使用EditText,setError
方法可以正常工作,但是我的样式设置会抛出下一个异常:
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)
这是EditText的XML
<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>
这是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>
这是产生错误的行:
emailInputLayout.setError("Incorrect email");
知道发生了什么事吗?
提前致谢,
答案 0 :(得分:12)
我发现错误,这些属性必须是样式:
<item name="android:textColorHighlight">@color/COLOR</item>
<item name="android:textColorLink">@color/COLOR</item>