Load a vector drawable into imageview from sd card

偶尔善良 提交于 2019-11-30 10:08:25

The BitmapFactory can't load vector drawables. You have to use the VectorDrawable or VectorDrawableCompat class. To load a vector drawable you need to use a xml loader.

Some parser like the one for the resources need a precompiled binary xml file. You can find them in the apk file when you put the vector drawable in the drawable resource directory.

Here is a sample to load it from the assets, you should be able to use a similar code for the loading from the sd card.

final XmlResourceParser parser = context.getAssets().openXmlResourceParser("assets/folder/image.xml");
drawable = VectorDrawableCompat.createFromXml(context.getResources(), parser);

This way needs at least Android 5.0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!