例如,在进行位图解码过程中,通常使用如下方法:
Bitmap bitmap2=BitmapFactory.decodeResource(getResources(), R.drawable.qq1);
如果想把文件名”qq1”作为变量,就不能用这种方法解码位图。
google中提供了一个方法:
int id1=getResources().getIdentifier("qq1","drawable","com.example.myqq");
这个方法得到了res/drawable/文件夹下qq1图片的id。
Drawable drawable1=getResources().getDrawable(id1);
这个方法就得到了qq1图片的Drawable。