Android 自定义EditText的setError图标
我想将Android 自定义EditText的setError图标,android,icons,textview,Android,Icons,Textview,我想将setError方法设置为myEditText,使用自定义图标而不是默认的Android图标。所以我试了一下: ((EditText)findViewById(R.id.edtTitle)).setError(getResources().getText(R.string.errEmptyTitle), getResources().getDrawable(R.drawable.ico_warning_small); 它显示自定义消息,但不显示自定义图标。我也试过这个
setError
方法设置为myEditText
,使用自定义图标而不是默认的Android图标。所以我试了一下:
((EditText)findViewById(R.id.edtTitle)).setError(getResources().getText(R.string.errEmptyTitle),
getResources().getDrawable(R.drawable.ico_warning_small);
它显示自定义消息,但不显示自定义图标。我也试过这个:
Drawable warning = (Drawable)getResources().getDrawable(R.drawable.ico_warning_small);
((EditText)findViewById(R.id.edtTitle))
.setError(getResources().getText(R.string.errEmptyTitle), warning);
差不多,但我还是决定试一试。然而,这也没有帮助-我仍然看不到图标。
我试着使用其他一些安卓系统图标,只是想看看我是否看到它们,不,我也没有看到它们
那么我做错了什么?有没有办法设置自定义图标?此处讨论并解决了此问题:
我希望通过扩展答案,它不会自动转换为注释。在setError中使用它之前,您需要设置绘图表的边界
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
editText.setError("error", drawable);
如果您根本不想显示任何图标,请使用
editText.setError("error", null);
看这里:@steellight非常感谢,它成功了!你能回答我的意见吗?这解决了我的问题。谢谢,谢谢-花了一个小时!
Drawable customErrorDrawable = getResources().getDrawable(R.drawable.error_icon);
customErrorDrawable.setBounds(0, 0, customErrorDrawable.getIntrinsicWidth(), customErrorDrawable.getIntrinsicHeight());
editText.setError("please enter data",customErrorDrawable);