我正在应用该setError()
方法TextInputLayout
,TextInputEditText
但出现此错误,
我想要实现的是错误工具提示。我没有心情使用任何第三方库来实现这一点。\
这是我尝试过的,但这些都不起作用,
TextInputLayout 中的错误即使调用 setErrorEnabled(true) 也不会再次显示
TextInputLayout setErrorEnabled 不会创建新的 TextView 对象
TextInputLayout.setError() 清除错误后留下空白空间
显示错误的 TextInputLayout 的 setError
在edittext中输入值后TextInputLayout错误
textinputlayout errorenabled 并显示错误
textinputlayout errorenabled 并显示错误
TextInputLayout的errorview在删除错误信息时没有被删除
摇篮
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'
错误堆栈跟踪,
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)
这是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>
这是我正在应用的内容,这正是引发错误的地方,
tilPassword.setError("Password required");
tilPassword.setErrorEnabled(true);