Android EditText错误消息d出文本未显示

Android EditText错误消息d出文本未显示,第1张

概述我在我的应用程序中遇到问题,其中EditTexts上的错误d出显示文本不可见. 它看起来像这样: 我的应用程序中的所有EditTexts都会发生这种情况. 这是一个布局XML的示例 布局: <?xml version="1.0" encoding="utf-8"?><android.support.design.widget.CoordinatorLayout xmlns:andro 我在我的应用程序中遇到问题,其中EditTexts上的错误d出显示但文本不可见.
它看起来像这样:

我的应用程序中的所有EditTexts都会发生这种情况.
这是一个布局XML的示例

布局:

<?xml version="1.0" enCoding="utf-8"?><androID.support.design.Widget.CoordinatorLayout    xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:app="http://schemas.androID.com/apk/res-auto"    xmlns:tools="http://schemas.androID.com/tools"    androID:ID="@+ID/main_content"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:background="@drawable/gradIEnt"    androID:fitsSystemwindows="true"    tools:context=".ui.onboarding.profile.OnboardingUserProfileActivity">    <ImageVIEw        androID:ID="@+ID/imageVIEw"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:scaleType="fitXY"        app:srcCompat="@drawable/shapes_background" />    <Progressbar        androID:ID="@+ID/login_progress"                androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_marginBottom="8dp"        androID:visibility="gone" />    <ScrollVIEw        androID:ID="@+ID/form"        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"        androID:layout_marginleft="20dp"        androID:layout_marginRight="20dp"        androID:layout_marginBottom="20dp">        <linearLayout            androID:ID="@+ID/linearLayout"            androID:layout_wIDth="match_parent"            androID:layout_height="wrap_content"            androID:layout_margintop="10dp"            androID:layout_marginBottom="80dp"            androID:orIEntation="vertical">            <androID.support.constraint.ConstraintLayout                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content"                androID:layout_gravity="center"                androID:layout_margintop="40dp"                androID:layout_marginBottom="20dp">                <ImageVIEw                    androID:ID="@+ID/profileImageVIEw"                    androID:layout_wIDth="160dp"                    androID:layout_height="160dp"                    androID:scaleType="fitXY"                    androID:src="@drawable/user_profile_placeholder"                    app:layout_constraintBottom_toBottomOf="parent"                    app:layout_constraintEnd_toEndOf="parent"                    app:layout_constraintStart_toStartOf="parent"                    app:layout_constrainttop_totopOf="parent"/>                <androID.support.design.Widget.floatingActionbutton                    androID:ID="@+ID/cameraimagebutton"                    androID:layout_wIDth="wrap_content"                    androID:layout_height="wrap_content"                    androID:layout_gravity="bottom|end"                    app:layout_constraintBottom_toBottomOf="parent"                    app:layout_constraintRight_toRightOf="parent"                    app:srcCompat="@androID:drawable/ic_menu_camera" />            </androID.support.constraint.ConstraintLayout>            <androID.support.design.Widget.TextinputLayout                androID:ID="@+ID/firstnameTvLayout"                androID:layout_wIDth="match_parent"                androID:layout_height="0dp"                androID:layout_marginBottom="20dp"                androID:layout_weight="0.33"                androID:textcolorHint="@color/colorVerylightGray"                androID:theme="@style/Apptheme.WhitecolorAccent"                app:errorTextAppearance="@style/error_appearance">                <androID.support.design.Widget.TextinputEditText                    androID:ID="@+ID/firstnameTv"                    androID:layout_wIDth="match_parent"                    androID:layout_height="wrap_content"                    androID:hint="@string/prompt_firstname"                    androID:inputType="textPersonname"                    androID:maxlines="1"                    androID:nextFocusDown="@ID/lastnameTv"                    androID:nextFocusForward="@ID/lastnameTv"                    androID:singleline="true"                    androID:textcolor="@androID:color/white"                    androID:textcolorHint="@color/colorWhite"                    androID:theme="@style/Apptheme.WhiteEditText"/>            </androID.support.design.Widget.TextinputLayout>            <androID.support.design.Widget.TextinputLayout                androID:ID="@+ID/lastnameTvLayout"                androID:layout_wIDth="match_parent"                androID:layout_height="0dp"                androID:layout_marginBottom="20dp"                androID:layout_weight="0.33"                androID:textcolorHint="@color/colorVerylightGray"                androID:theme="@style/Apptheme.WhitecolorAccent">                <androID.support.design.Widget.TextinputEditText                    androID:ID="@+ID/lastnameTv"                    androID:layout_wIDth="match_parent"                    androID:layout_height="wrap_content"                    androID:hint="@string/prompt_lastname"                    androID:inputType="textPersonname"                    androID:maxlines="1"                    androID:nextFocusDown="@ID/usernameTv"                    androID:nextFocusForward="@ID/usernameTv"                    androID:singleline="true"                    androID:textcolor="@androID:color/white"                    androID:textcolorHint="@color/colorWhite"                    androID:theme="@style/Apptheme.WhiteEditText" />            </androID.support.design.Widget.TextinputLayout>            <androID.support.design.Widget.TextinputLayout                androID:ID="@+ID/usernameTvLayout"                androID:layout_wIDth="match_parent"                androID:layout_height="0dp"                androID:layout_weight="0.33"                androID:textcolorHint="@color/colorVerylightGray"                androID:theme="@style/Apptheme.WhitecolorAccent">                <androID.support.design.Widget.TextinputEditText                    androID:ID="@+ID/usernameTv"                    androID:layout_wIDth="match_parent"                    androID:layout_height="wrap_content"                    androID:hint="@string/prompt_username"                    androID:imeActionID="6"                    androID:imeActionLabel="@string/action_sign_in_short"                    androID:imeOptions="actionUnspecifIEd"                    androID:maxlines="1"                    androID:nextFocusDown="@ID/nextBtn"                    androID:nextFocusForward="@ID/nextBtn"                    androID:singleline="true"                    androID:textcolor="@androID:color/white"                    androID:textcolorHint="@color/colorWhite"                    androID:theme="@style/Apptheme.WhiteEditText" />            </androID.support.design.Widget.TextinputLayout>        </linearLayout>    </ScrollVIEw>    <button        androID:ID="@+ID/nextBtn"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:layout_marginBottom="10dp"        androID:layout_marginleft="50dp"        androID:layout_marginRight="50dp"        androID:layout_margintop="16dp"        androID:text="@string/next"        androID:textStyle="bold"        androID:theme="@style/Apptheme.Primarybutton"        app:layout_anchor="@+ID/form"        app:layout_anchorGravity="bottom|center_horizontal" /></androID.support.design.Widget.CoordinatorLayout>

和风格:

<style name="Apptheme.WhitecolorAccent">    <item name="colorAccent">@color/colorWhite</item></style>  <style name="Apptheme.WhiteEditText" parent="Widget.AppCompat.EditText">    <item name="androID:textcolor">@color/colorWhite</item>    <item name="colorControlnormal">@color/colorVerylightGray</item>    <item name="colorControlActivated">@color/colorWhite</item>    <item name="colorControlHighlight">@color/colorWhite</item></style>

使用firstnameTv.error设置活动中的错误=“此字段不能为空”(Kotlin)

解决方法 你需要使用
风格= “@风格/ Apptheme.WhiteEditText”

而不是androID:theme =“@ style / Apptheme.WhitecolorAccent”

Now question is why need to use style Instead of androID:theme

使用样式时,它仅适用于该视图

当你使用androID:theme时,它将应用视图以及它的所有子项.

阅读更多关于What is the difference between style and android:theme attributes?

示例代码

<?xml version="1.0" enCoding="utf-8"?><androID.support.design.Widget.CoordinatorLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:app="http://schemas.androID.com/apk/res-auto"    xmlns:tools="http://schemas.androID.com/tools"    androID:ID="@+ID/main_content"    androID:layout_wIDth="match_parent"    androID:fitsSystemwindows="true"    androID:layout_height="match_parent"    androID:background="@color/colorPrimary">    <ImageVIEw        androID:ID="@+ID/imageVIEw"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:scaleType="fitXY"        androID:visibility="gone" />    <Progressbar        androID:ID="@+ID/login_progress"                androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_marginBottom="8dp"        androID:visibility="gone" />    <ScrollVIEw        androID:ID="@+ID/form"        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"        androID:layout_marginleft="20dp"        androID:layout_marginRight="20dp"        androID:layout_marginBottom="20dp"        androID:fillVIEwport="true">        <linearLayout            androID:ID="@+ID/linearLayout"            androID:layout_wIDth="match_parent"            androID:layout_height="wrap_content"            androID:layout_margintop="10dp"            androID:layout_marginBottom="80dp"            androID:orIEntation="vertical">            <androID.support.constraint.ConstraintLayout                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content"                androID:layout_gravity="center"                androID:layout_margintop="40dp"                androID:layout_marginBottom="20dp">                <ImageVIEw                    androID:ID="@+ID/profileImageVIEw"                    androID:layout_wIDth="160dp"                    androID:layout_height="160dp"                    androID:scaleType="fitXY"                    androID:src="@color/colorNavbar"                    app:layout_constraintBottom_toBottomOf="parent"                    app:layout_constraintEnd_toEndOf="parent"                    app:layout_constraintStart_toStartOf="parent"                    app:layout_constrainttop_totopOf="parent" />                <androID.support.design.Widget.floatingActionbutton                    androID:ID="@+ID/cameraimagebutton"                    androID:layout_wIDth="wrap_content"                    androID:layout_height="wrap_content"                    androID:layout_gravity="bottom|end"                    app:layout_constraintBottom_toBottomOf="parent"                    app:layout_constraintRight_toRightOf="parent"                    app:srcCompat="@androID:drawable/ic_menu_camera" />            </androID.support.constraint.ConstraintLayout>            <androID.support.design.Widget.TextinputLayout                androID:ID="@+ID/firstnameTvLayout"                androID:layout_wIDth="match_parent"                androID:layout_height="0dp"                androID:layout_marginBottom="20dp"                androID:layout_weight="0.33"                androID:textcolorHint="@color/colorVerylightGray"                                >                <androID.support.design.Widget.TextinputEditText                    androID:ID="@+ID/firstnameTv"                    androID:layout_wIDth="match_parent"                    androID:layout_height="wrap_content"                    androID:hint="First name"                    androID:inputType="textPersonname"                    androID:maxlines="1"                    androID:imeOptions="actionNext"                    androID:nextFocusDown="@ID/lastnameTv"                    androID:nextFocusForward="@ID/lastnameTv"                    androID:textcolor="@androID:color/white"                    androID:textcolorHint="@color/colorWhite"                     />            </androID.support.design.Widget.TextinputLayout>            <androID.support.design.Widget.TextinputLayout                androID:ID="@+ID/lastnameTvLayout"                androID:layout_wIDth="match_parent"                androID:layout_height="0dp"                androID:layout_marginBottom="20dp"                androID:layout_weight="0.33"                androID:textcolorHint="@color/colorVerylightGray"                >                <androID.support.design.Widget.TextinputEditText                    androID:ID="@+ID/lastnameTv"                    androID:layout_wIDth="match_parent"                    androID:layout_height="wrap_content"                    androID:hint="Last name"                    androID:inputType="textPersonname"                    androID:maxlines="1"                    androID:nextFocusDown="@ID/usernameTv"                    androID:nextFocusForward="@ID/usernameTv"                    androID:singleline="true"                    androID:textcolor="@androID:color/white"                    androID:textcolorHint="@color/colorWhite"                     />            </androID.support.design.Widget.TextinputLayout>            <androID.support.design.Widget.TextinputLayout                androID:ID="@+ID/usernameTvLayout"                androID:layout_wIDth="match_parent"                androID:layout_height="0dp"                androID:layout_marginBottom="20dp"                androID:layout_weight="0.33"                androID:textcolorHint="@color/colorVerylightGray"                >                <androID.support.design.Widget.TextinputEditText                    androID:ID="@+ID/usernameTv"                    androID:layout_wIDth="match_parent"                    androID:layout_height="wrap_content"                    androID:hint="user name"                    androID:imeActionID="6"                    androID:imeActionLabel="AB"                    androID:imeOptions="actionUnspecifIEd"                    androID:maxlines="1"                    androID:nextFocusDown="@ID/nextBtn"                    androID:nextFocusForward="@ID/nextBtn"                    androID:singleline="true"                    androID:textcolor="@androID:color/white"                    androID:textcolorHint="@color/colorWhite"                     />            </androID.support.design.Widget.TextinputLayout>        </linearLayout>    </ScrollVIEw>    <button        androID:ID="@+ID/nextBtn"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:layout_marginBottom="10dp"        androID:layout_marginleft="50dp"        androID:layout_marginRight="50dp"        androID:layout_margintop="16dp"        androID:text="Next"        androID:textStyle="bold"        app:layout_anchor="@+ID/form"        app:layout_anchorGravity="bottom|center_horizontal" /></androID.support.design.Widget.CoordinatorLayout>

style

<style name="Apptheme.WhitecolorAccent">    <item name="colorAccent">@color/colorWhite</item></style><style name="Apptheme.WhiteEditText" parent="Widget.AppCompat.EditText">    <item name="androID:textcolor">@color/colorWhite</item>    <item name="colorControlnormal">@color/colorVerylightGray</item>    <item name="colorControlActivated">@color/colorWhite</item>    <item name="colorControlHighlight">@color/colorWhite</item></style>

OUTPUT

总结

以上是内存溢出为你收集整理的Android EditText错误消息d出文本未显示全部内容,希望文章能够帮你解决Android EditText错误消息d出文本未显示所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1149558.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存