0

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.

4

2 回答 2

1

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);
于 2012-10-22T05:20:15.900 回答
0

All resources in your project is parsed under R class automatically. You should always retrive them as an object, such as: R.drawable.drawable_name This is a basic way to retrieve many resource types. Just replace drawable keyword such as: R.string.name_of_string_resource R.id.id_control

于 2012-10-22T05:50:58.273 回答