/获取图片资源的ID
mImageView=(ImageView) findViewById(R.id.imageView);
int drawableId = mContext.getResources().getIdentifier("ic_launcher","drawable", mContext.getPackageName());
mImageView.setImageResource(drawableId);
System.out.println("----> 获取到的图片资源 drawableId="+drawableId);
//获取字符串资源
mTextView=(TextView) findViewById(R.id.textView);
int stringId = mContext.getResources().getIdentifier("hello","string", mContext.getPackageName());
mTextView.setText(stringId);
System.out.println("----> 获取到的字符串资源 stringId="+stringId);
---------------------
原文:https://blog.csdn.net/gao_chun/article/details/45891383