-6

I need put text and image into button and need do it dynamically. I know how do it in xml code but I can`t transfer it to java code.

Vimal Bera
  • 10,155
  • 4
  • 23
  • 47
marusinm
  • 31
  • 3

2 Answers2

1

Try this,

Button b=new Button(this);
        b.setCompoundDrawablePadding(10);
        b.setCompoundDrawablesWithIntrinsicBounds(R.drawable.icon, 0, 0, 0);
Andro Selva
  • 53,136
  • 52
  • 190
  • 238
0

try this code:

button.setCompoundDrawables(Drawable left,Drawable top,Drawable right,Drawable bottom);
shiju B
  • 1,690
  • 10
  • 23