Skip to content Skip to sidebar Skip to footer

How Can I Set The Drawableright Resource Via Code?

I am trying to set an image on the right side of my button after the button has been clicked. I want to do this via code. I have seen how to change the background resource via cod

Solution 1:

You need to use the

public void setCompoundDrawables (Drawable left, Drawable top, Drawable right, 
 Drawable bottom)

method with null for any that are not needed.

Solution 2:

Usually you can change using this

Drawabledraw= getResources().getDrawable(R.drawable.facebook);
myButton.setCompoundDrawablesWithIntrinsicBounds(null, null, draw, null);

Be aware you can miss the button text.

Post a Comment for "How Can I Set The Drawableright Resource Via Code?"