Android 如何设置多媒体资料的背景图像
我想通过Drawable文件夹中的图像(比如background.jpg)设置我的图库的背景 setBackground()方法的原型是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.
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控制