editTextField = findViewById<EditText>(R.id.nameText)
editTextField.setError(“error message”)
出于某种原因,错误消息带有深色背景和黑色文本的不可读组合。这个问题的旧答案是关于从HTML方法中弃用的......
答案 0 :(得分:0)
<强> 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);
}
使用它与标志参数
的 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;
答案 1 :(得分:0)
试试这个
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);