Monday, July 30, 2012

Display a icon/image on button using Java code

The method setCompoundDrawablesWithIntrinsicBounds(int left, int top, int right, int bottom) sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text. Use 0 if you do not want a Drawable there. The Drawables' bounds will be set to their intrinsic bounds.

example:
        Button imageButton = (Button)findViewById(R.id.imagebutton);
        imageButton.setCompoundDrawablesWithIntrinsicBounds(
          0,     //left 
          0,      //top
          R.drawable.icon,  //right
          0);     //bottom


Display a icon/image on button using Java code

No comments:

Post a Comment