gpt4 book ai didi

android - SetError 在 TextInputLayout 中使用自定义样式产生异常

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:34:06 25 4
gpt4 key购买 nike

我在使用自定义样式的 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");

知道发生了什么事吗?

提前致谢

最佳答案

我发现了错误,这些属性必须在样式中:

<item name="android:textColorHighlight">@color/COLOR</item>
<item name="android:textColorLink">@color/COLOR</item>

关于android - SetError 在 TextInputLayout 中使用自定义样式产生异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37773889/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com