我正在使用 TextInputLayout 小部件,我只想在视图的末尾显示错误图标,而不考虑错误消息。
3 回答
0
如果要显示错误图标,唯一的内置方法是显示消息错误:
textInputLayout.setError("Error message");
如果要显示错误图标而不显示错误消息,则有一种解决方法:
//Update the EndIcon with a custom icon error
textInputLayout.setEndIconMode(TextInputLayout.END_ICON_CUSTOM);
textInputLayout.setEndIconDrawable(R.drawable.error_icon);
//Tint the end icon with the error color defined in your app theme
TypedValue typedValue = new TypedValue();
getTheme().resolveAttribute(R.attr.colorError, typedValue, true);
textInputLayout.setEndIconTintList(
ContextCompat.getColorStateList(this,typedValue.resourceId));
于 2020-07-25T18:13:17.040 回答
0
如果要更改错误图标并显示错误,请使用
val errorDrawable = ContextCompat.getDrawable(context!!, R.drawable.ic_error)
input_layout.error = SpannableString("error message").apply {
setSpan(ImageSpan(errorDrawable, ImageSpan.ALIGN_BASELINE), 0, 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
于 2020-07-25T17:42:50.147 回答
-3
kotlin
请为此目的使用以下行
yourInputLayout.error = "Please enter valid email address"
于 2020-07-25T17:37:29.927 回答