EditText setError 图片不显示问题

txtUserpwd.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(R.drawable.indicator_input_error), null);
txtUserpwd.setError(getResources().getString(R.string.input_userpwd));
txtUserpwd.requestFocus();

这么做图片是显示的手机默认图片而不是你自定义图片,原因为没有给图片设置大小

Drawable errorIcon = getResources().getDrawable(R.drawable.indicator_input_error);
errorIcon.setBounds(new Rect(0, 0, errorIcon.getIntrinsicWidth(),errorIcon.getIntrinsicHeight()));//设置图片大小
ForegroundColorSpan fgcspan = new ForegroundColorSpan(getResources().getColor(R.color.red));//将提示文字 改为红色
SpannableStringBuilder ssbuilder = new SpannableStringBuilder(getResources().getString(R.string.input_username));
ssbuilder.setSpan(fgcspan, 0,getResources().getString(R.string.input_username).length(), 0);
txtUserpwd.setError(ssbuilder, errorIcon);
txtUserpwd.requestFocus();

原文地址:https://www.cnblogs.com/freexiaoyu/p/2830521.html