Skip to content Skip to sidebar Skip to footer

Setcompounddrawableswithintrinsicbounds Is Not Working Properly

I've an email field as EditText. I'm trying to add a green-tick icon at the end of the text field when the validation is true, and setError when it is false. Here's the piece of co

Solution 1:

try removing the icon from xml if you are setting any and set both images from the code for some reason the image does not refresh if you set one from xml

and use

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
          numTxt.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.icon, 0, 0, 0);
    } else {    
          numTxt.setCompoundDrawablesWithIntrinsicBounds(R.drawable.icon, 0, 0, 0);
    }

Solution 2:

I am not sure if this is a bug but I am able to workaround this by setting the drawable to zero (0) first before assigning the new drawable.

In your case, you can try the following:

Log.i("YaY","Email is valid!!!");
email.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
email.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.validated, 0);

Post a Comment for "Setcompounddrawableswithintrinsicbounds Is Not Working Properly"