How To Set Bitmap Image To Button Background Image
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_
Solution 1:
You can use following code to do that..
BitmapDrawablebdrawable=newBitmapDrawable(context.getResources(),bitmap);
then just set bitmap with below function
button.setBackground(bdrawable);
Solution 2:
you need to check current version of Android also
Button bProfile; // your Button
Bitmap bitmap; // your bitmapif(android.os.Build.VERSION.SDK_INT < 16) {
bProfile.setBackgroundDrawable(new BitmapDrawable(getResources(), bitmap));
}
else {
bProfile.setBackground(new BitmapDrawable(getResources(),bitmap));
}
Solution 3:
Hey First learn about Handling bitmaps: http://developer.android.com/training/displaying-bitmaps/process-bitmap.html
You should not process bitmaps on the UI thread at all. Once you have attained Bitmap use ImageView's method setImageBitmap(Bitmap bitmap).
To fetch images through network, You can also use libraries like picasso, Universal Image Loader, Volley to attain what you are wanting.
Solution 4:
I always and will always recommended you strongly using Image Button.
http://developer.android.com/reference/android/widget/ImageButton.html
I hope that helps you, Shaun.
Post a Comment for "How To Set Bitmap Image To Button Background Image"