哪个主题属性更改 EditText 错误消息的文本颜色

发布于 2024-11-25 12:21:39 字数 338 浏览 4 评论 0原文

在我的表单中,我在 EditText 字段上使用 setError("")。我的应用程序主题扩展了 android:Theme.Holo
我已为 android:errorMessageBackgroundandroid:errorMessageAboveBackground 手动设置了深色背景的图像。

现在的问题是:错误消息的文本颜色也很暗且不可读。

我尝试更改主题中的不同 textColor 属性,但无法找到正确的属性。

有人可以帮助我吗?

In my form, I use setError("") on an EditText field. My Application-Theme extends android:Theme.Holo.
I have manually set an image with a dark background for android:errorMessageBackground and android:errorMessageAboveBackground.

And now here's the problem: The text color of the error message is also very dark and not readable.

I tried changing different textColor attributes in my Theme, but I wasn't able to find the correct one.

Can anyone could help me, please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

还不是爱你 2024-12-02 12:21:39

您可以使用HTML 字体标签更改文本颜色。

但是要自定义背景颜色,您应该创建自己的自定义弹出窗口。
欲了解更多信息,请访问此链接:-
如何将样式写入 EditText 中的错误文本安卓?

You can change the text color by using HTML Font Tag.

But for customizing background color, you should make your own custom pop up.
For more information, Kindly go through this link:-
How to write style to error text of EditText in android?

紧拥背影 2024-12-02 12:21:39

你可以试试这个:

editText.setError(Html.fromHtml("<font color='red'>Error Message!</font>"));

You can try this one:

editText.setError(Html.fromHtml("<font color='red'>Error Message!</font>"));
塔塔猫 2024-12-02 12:21:39

在manifest.xml中执行以下操作

<resources>
    <style name="LightErrorFix" parent="@android:style/Theme.Light">
         <item name="android:textColorSecondaryInverse">@android:color/secondary_text_light</item>
    </style>
</resources>

do following in manifest.xml

<resources>
    <style name="LightErrorFix" parent="@android:style/Theme.Light">
         <item name="android:textColorSecondaryInverse">@android:color/secondary_text_light</item>
    </style>
</resources>
烟柳画桥 2024-12-02 12:21:39

假设你做了这样的事情:

EditText text = (EditText) findViewById(R.id.myedittext);

你可以执行以下操作:

text.setTextColor(Color.parseColor("#FFFFFF"));

或者

text.setTextColor(Color.rgb(200,0,0));

或者如果你想要/需要阿尔法:

text.setTextColor(Color.argb(0,200,0,0));

无论如何,你应该在你的 color.xml 中指定你的颜色(更好地维护):

<color name="myColor">#f00</color>

然后像这样使用它

text.setTextColor(getResources().getColor(R.color.myColor));

:乐趣 :)

Assuming you did sth like this:

EditText text = (EditText) findViewById(R.id.myedittext);

you can do the following:

text.setTextColor(Color.parseColor("#FFFFFF"));

or

text.setTextColor(Color.rgb(200,0,0));

or if you want/need alpha:

text.setTextColor(Color.argb(0,200,0,0));

Anyhow, you should specify your colors in your color.xml (wayyy better to be maintained):

<color name="myColor">#f00</color>

and then use it like this:

text.setTextColor(getResources().getColor(R.color.myColor));

Have fun :)

掌心的温暖 2024-12-02 12:21:39

设置属性
android:textColorPrimaryInverse="YourCOLOR" 为所需的颜色。

set the property
android:textColorPrimaryInverse="YourCOLOR" to the color nedded.

静待花开 2024-12-02 12:21:39

我的回复有效,是在 kotlin 中。

private fun setErrorOnSearchView(searchView: SearchView, errorMessage: String) {
    val id = searchView.context
            .resources
            .getIdentifier("android:id/search_src_text", null, null)
    val editText = searchView.find<EditText>(id)

    val errorColor = ContextCompat.getColor(this,R.color.red)
    val fgcspan = ForegroundColorSpan(errorColor)
    val builder = SpannableStringBuilder(errorMessage)
    builder.setSpan(fgcspan, 0, errorMessage.length, 0)
    editText.error = builder
}

My response works, is in kotlin.

private fun setErrorOnSearchView(searchView: SearchView, errorMessage: String) {
    val id = searchView.context
            .resources
            .getIdentifier("android:id/search_src_text", null, null)
    val editText = searchView.find<EditText>(id)

    val errorColor = ContextCompat.getColor(this,R.color.red)
    val fgcspan = ForegroundColorSpan(errorColor)
    val builder = SpannableStringBuilder(errorMessage)
    builder.setSpan(fgcspan, 0, errorMessage.length, 0)
    editText.error = builder
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文