我在imageButton上显示图片有问题...
imgWeatherIcon = (ImageButton) findViewById(R.id.mndpImage);
Intent i = getIntent();
this.iconfile = i.getStringExtra("icon");
String uri = "drawable/"+ "d" + iconfile;
System.out.println("* "+ uri);
int imageBtnResource = getResources().getIdentifier(uri, null, getPackageName());
Drawable dimgbutton = getResources().getDrawable(imageBtnResource);
imgWeatherIcon.setImageDrawable(dimgbutton);
一些System.out.println输出:
uri = drawable/dsnowing
imageBtnResource = 2130837512
dimgbutton = android.graphics.drawable.BitmapDrawable@414733c8
图像存在于drawable文件夹中 布局中imageButton元素(mndpImage)的名称是正确的
任何想法如何解决这个问题?
答案 0 :(得分:0)
这有用吗?
imgWeatherIcon = (ImageButton) findViewById(R.id.mndpImage);
imgWeatherIcon.setBackgroundResource(R.drawable.dsnowing);