Which theme attribute changes the text color of an EditText's error message

て烟熏妆下的殇ゞ 提交于 2019-12-01 02:14:29
Pradeep

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?

You can try this one:

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

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>

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 :)

user3862505

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

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
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!