IDE环境:Android Studio 2.2.1
android studio默认没有assets目录,所以需要首先建立该目录,目录所在路径 android module/src/main(注意assets中所有字母都为小写)
下面就用一段代码进行assets下的图片引用:
<pre>
ImageView mImageView = (ImageView) findViewById(R.id.image);
AssetManager am = getAssets();
InputStream is =null;
try {
is = am.open("play.png");
Bitmap bitmap = BitmapFactory.decodeStream(is);
mImageView.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}finally {
if(is !=null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
</pre>