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

在我的表单中,我在EditText字段上使用了setError("") 。 我的应用程序主题扩展了android:Theme.Holo
我有手动设置一个图像与黑暗的背景为android:errorMessageBackgroundandroid:errorMessageBackgroundAbove

现在,这是问题:错误信息的文本颜色也是非常黑暗,不可读。

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

任何人都可以帮助我吗? 谢谢! 克里斯

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

但是为了自定义背景颜色,你应该使自己的自定义popup。 欲了解更多信息,请通过下面的链接: – 如何编写样式到Android的EditText错误文本?

你可以试试这个:

 editText.setError(Html.fromHtml("Error Message!")); 

在manifest.xml中执行以下操作

    

假设你这样做了:

 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中指定你的颜色(最好保持原样):

 #f00 

然后像这样使用它:

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

玩的开心 :)

将属性android:textColorPrimaryInverse="YourCOLOR"设置为nedded的颜色。

我的回应是有效的,在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(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 }