Is it possible to load a drawable from the assets folder?

后端 未结 8 1680
刺人心
刺人心 2020-12-08 06:43

Can you load a drawable from a sub directory in the assets (not the drawable folder) folder?

8条回答
  •  一个人的身影
    2020-12-08 06:59

    This helped getting the right density

    private Drawable drawableFromAssetFilename(String filename) {
        AssetManager assetManager = mApplicationContext.getAssets();
        InputStream inputStream = null;
        try {
            inputStream = assetManager.open(filename);
        } catch (IOException e) {
            e.printStackTrace();
        }
        Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
    
        BitmapDrawable drawable = new BitmapDrawable(mApplicationContext.getResources(), bitmap);
        return drawable;
    }
    

提交回复
热议问题