Customizing the setError icon for TextView

后端 未结 4 2126
有刺的猬
有刺的猬 2020-12-15 19:51

I want to set a setError method to my TextView, with a custom icon instead of the default Android icon. So I tried this:

((EditText         


        
相关标签:
4条回答
  • 2020-12-15 19:58
        Drawable customErrorDrawable = getResources().getDrawable(R.drawable.error_icon);
            customErrorDrawable.setBounds(0, 0, customErrorDrawable.getIntrinsicWidth(), customErrorDrawable.getIntrinsicHeight());
    
    
     editText.setError("please enter data",customErrorDrawable);
    
    0 讨论(0)
  • 2020-12-15 20:01

    If you don't want to show any icon at all, use

    editText.setError("error", null);
    
    0 讨论(0)
  • 2020-12-15 20:18

    You need to set the bounds on the drawable before using it in setError.

    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    editText.setError("error", drawable);
    
    0 讨论(0)
  • 2020-12-15 20:20

    This issue is discussed and resolved here:

    EditText setError() with icon but without Popup message

    I hope that by extending the answer it would not get auto-converted to a comment.

    0 讨论(0)
提交回复
热议问题