gpt4 book ai didi

android - Android 中的 InputTextLayout setError() 方法不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:52:47 26 4
gpt4 key购买 nike

我设计了一个包含自定义 Edittext 的自定义 InputTextLayout。此自定义 Edittext 扩展了“AppCompatEdittext”。我的 MainActivity 也扩展了 AppCompatActivity。但我仍然无法使用 TextInputLayout 显示错误消息。以下是我来自各种文件的代码 fragment 。

主.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>

主 Activity .java

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

来自 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>

并显示错误。

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) 

最佳答案

也尝试设置以下属性:

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

关于android - Android 中的 InputTextLayout setError() 方法不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35313549/

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