ITPub博客

首页 > IT职业 > IT图书 > android 下的 assets目录

android 下的 assets目录

IT图书 作者:llittle 时间:2021-09-09 09:03:09 0 删除 编辑

assets文件在打包后会原封不动的保存在apk包中,不会被编译成二进制。

assets可以建立多级目录

assets文件夹下的文件不会被映射到R.java中,访问的时候需要AssetManager类。

下面是一个封装好的获取Bitmap资源的工具类:


 public static Bitmap getBitmapFromAsset(Context context, String filePath) {
  AssetManager assetManager = context.getAssets();

  InputStream istr;
  Bitmap bitmap = null;
  try {
    istr = assetManager.open(filePath);
    bitmap = BitmapFactory.decodeStream(istr);
  } catch (IOException e) {
    // handle exception
  }

  return bitmap;
}

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/813/viewspace-2798946/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-12

  • 博文量
    448
  • 访问量
    4362