Search code examples
androidandroid-gallery

How to set background image for Gallery


I want to set the background of my Gallery by an image (say background.jpg ) in Drawable folder.

As the prototype of the setBackground() method is

 void   setBackground(Drawable background)
Set the background to a given Drawable, or remove the background.

But I don't know how to refer to my image in this method. I have tried to refer like this

Gallery galleryModified;
galleryModified.setBackground(background);

But getting error in second line, saying unable to find resource.

Please reply if you know.

Thanks.


Solution

  • It seems, you are setting background from a resource from drawable folder, which have id, R.drawable.background, if it is the case, try following:

    galleryModified.setBackgroundResource(R.drawable.background);