I am using picasso library to load images from server. I can set background image to ImageView using Picasso. But I could not set background image using same. I have also try different method to set Image to activity layout background. Plaese help me.
My code is as follows:
Picasso.with(getApplicationContext()).load("https://cms-assets.tutsplus.com/uploads/users/21/posts/19431/featured_image/CodeFeature.jpg").into(new Target() {
@Override
public void onPrepareLoad(Drawable arg0) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Start Loading", Toast.LENGTH_SHORT).show();
}
@Override
public void onBitmapLoaded(Bitmap bitmap, LoadedFrom arg1) {
// TODO Auto-generated method stub
loginLayout.setBackground(new BitmapDrawable(getApplicationContext().getResources(), bitmap));
}
@Override
public void onBitmapFailed(Drawable arg0) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Failed Loading", Toast.LENGTH_SHORT).show();
}
});
Try using setBackgroundDrawable instead of setBackground
@Override
public void onBitmapLoaded(Bitmap bitmap, LoadedFrom arg1) {
// TODO Auto-generated method stub
loginLayout.setBackgroundDrawable(new BitmapDrawable(getApplicationContext().getResources(), bitmap));
}