How to set bitmap image to Button Background Image

Viresh picture Viresh · Sep 23, 2013 · Viewed 15.8k times · Source
gridcell = (Button) row.findViewById(R.id.calendar_day_gridcell);    
gridcell.setText("Day 1");    
URL url = new URL("http://172.16.4.29:81/pht/2013/9/18/3027_2013_9_18_12_14_56_b.JPG");
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());

How can I set bitmap bmp image to button gridcells background Image?

Answer

Chintan Rathod picture Chintan Rathod · Sep 23, 2013

You can use following code to do that..

BitmapDrawable bdrawable = new BitmapDrawable(context.getResources(),bitmap);

then just set bitmap with below function

button.setBackground(bdrawable);