0
imageView1.setBackgroundResource(R.raw.background);
为:
String imageSel= "background"
imageView1.setBackgroundResource(R.raw.imageSel);
我如何使用这个使用imageSel
变量?请让我知道
imageView1.setBackgroundResource(R.raw.background);
为:
String imageSel= "background"
imageView1.setBackgroundResource(R.raw.imageSel);
我如何使用这个使用imageSel
变量?请让我知道
我该如何使用这个imageSel变量?
使用getIdentifier
使用资源名称来获得资源ID:
int rawId = getResources().getIdentifier(background, "raw", getPackageName());
imageView1.setBackgroundResource(rawId);
感谢亚尔。但是我正在解决一些问题。不知何故,它不在我的代码中工作。在这里, 原始文件夹是我在我的照片名称中保存了我的照片和背景的文件夹。 –
@SiamAaron:我有一个问题,为什么你在'raw'文件夹中添加了图像,因为对于'drawable'图像,'drawable-mdpi',..文件夹是可用的? –
起初我通过观看教程来创建应用程序。这就是为什么它在原始文件夹 –