Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何设置多媒体资料的背景图像_Android_Android Gallery - Fatal编程技术网

Android 如何设置多媒体资料的背景图像

Android 如何设置多媒体资料的背景图像,android,android-gallery,Android,Android Gallery,我想通过Drawable文件夹中的图像(比如background.jpg)设置我的图库的背景 setBackground()方法的原型是 void setBackground(Drawable background) Set the background to a given Drawable, or remove the background. 但我不知道如何在这种方法中引用我的图像。 我试着这样称呼他 Gallery galleryModified; galleryModified.

我想通过Drawable文件夹中的图像(比如background.jpg)设置我的图库的背景

setBackground()方法的原型是

 void   setBackground(Drawable background)
Set the background to a given Drawable, or remove the background.
但我不知道如何在这种方法中引用我的图像。 我试着这样称呼他

Gallery galleryModified;
galleryModified.setBackground(background);
但第二行出现错误,表示无法找到资源

如果你知道,请回复


谢谢。

您似乎正在从drawable文件夹中的资源设置背景,该文件夹的id为R.drawable.background,如果是这样,请尝试以下操作:

galleryModified.setBackgroundResource(R.drawable.background);

项目中的所有资源都会在R类下自动解析。您应该始终将它们作为对象检索,例如:
R.drawable.drawable\u name
这是检索许多资源类型的基本方法。只需替换
drawable
关键字,例如:
R.string.字符串资源的名称
R.id.id\u控制