Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setCompoundDrawablesWithIntrinsicBounds(int,int,int,int) not working

I have a few EditText views where I want to set the image on the left and setCompoundDrawablesWithIntrinsicBounds does not seems to be working. The graphics do not seem to be getting changed.

does anyone know why this might be the case?

Here is how I am setting the drawables:

        mFirstname.setCompoundDrawablesWithIntrinsicBounds(R.drawable.user_icon, 0, 0, 0);
        mLastname.setCompoundDrawablesWithIntrinsicBounds(R.drawable.user_icon, 0, 0, 0);
        mEmail.setCompoundDrawablesWithIntrinsicBounds(R.drawable.mailicon, 0, 0, 0);
        mPassword.setCompoundDrawablesWithIntrinsicBounds(R.drawable.lockicon, 0, 0, 0);
        mDateOfBirth.setCompoundDrawablesWithIntrinsicBounds(R.drawable.calico, 0, 0, 0);
        mCity.setCompoundDrawablesWithIntrinsicBounds(R.drawable.mailicon, 0, 0, 0);
        mStreet.setCompoundDrawablesWithIntrinsicBounds(R.drawable.mailicon, 0, 0, 0);
        mPostcode.setCompoundDrawablesWithIntrinsicBounds(R.drawable.mailicon, 0, 0, 0);
        mPhoneNumber.setCompoundDrawablesWithIntrinsicBounds(R.drawable.mailicon, 0, 0, 0);
like image 277
jimbob Avatar asked Dec 06 '13 12:12

jimbob


2 Answers

If anyone else has this seemingly unexplainable issue then try the following:

  • Go to your XML template.
  • Remove the XML image representing it.
  • Your view should refresh the compounddrawable.

basically this portion of the view does not seem to get reinflated on ICS devices. Hopefully this solves the problem for some people!

like image 150
jimbob Avatar answered Nov 03 '22 00:11

jimbob


Another solution is to setup compound drawable on the next (after layout) cycle of the UI loop:

final TextView viewById = (TextView) findViewById(R.id.label);

viewById.post(new Runnable()
{
    @Override
    public void run()
    {
        viewById.setCompoundDrawablesWithIntrinsicBounds(android.R.drawable.ic_menu_call, 0, 0, 0);
    }
});
like image 43
Denis Gladkiy Avatar answered Nov 03 '22 02:11

Denis Gladkiy