[英]Changing text color for setError method for editText fields
editTextField = findViewById<EditText>(R.id.nameText)
editTextField.setError(“error message”)
For some reason the error messages come with an unreadable combination of darkish background and black text. 由于某种原因,错误消息带有深色背景和黑色文本的不可读组合。 The old answers for this question are about a deprecated fromHtml method... 这个问题的旧答案是关于不推荐使用的fromHtml方法...
Try This To Use Html.fromHtml() in all APIs
:- Try This To Use Html.fromHtml() in all APIs
:
@SuppressWarnings("deprecation")
public static Spanned fromHtml(String html)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY);
} else{
return Html.fromHtml(html);
}
Just Use It With Flag Parameter 只需将其与标志参数一起使用
Flag Parameters Are
:- Flag Parameters Are
:
public static final int FROM_HTML_MODE_COMPACT = 63;
public static final int FROM_HTML_MODE_LEGACY = 0;
public static final int FROM_HTML_OPTION_USE_CSS_COLORS = 256;
public static final int FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE = 32;
public static final int FROM_HTML_SEPARATOR_LINE_BREAK_DIV = 16;
public static final int FROM_HTML_SEPARATOR_LINE_BREAK_HEADING = 2;
public static final int FROM_HTML_SEPARATOR_LINE_BREAK_LIST = 8;
public static final int FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM = 4;
public static final int FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH = 1;
public static final int TO_HTML_PARAGRAPH_LINES_CONSECUTIVE = 0;
public static final int TO_HTML_PARAGRAPH_LINES_INDIVIDUAL = 1;
Try this 尝试这个
String errorString = "This field cannot be empty"; // Your custom error message.
ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(errorColor);
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(errorString);
spannableStringBuilder.setSpan(foregroundColorSpan, 0, errorString.length(), 0);
editTextView.setError(spannableStringBuilder);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.