Easiest way to use SVG in Android?

前端 未结 8 1000
一个人的身影
一个人的身影 2020-12-02 05:35

I have found a myriad of libraries in order to use svg in Android and avoid the frustrating creation of different resolutions and dropping files for each resolution, this be

8条回答
  •  庸人自扰
    2020-12-02 05:45

    1. you need to convert SVG to XML to use in android project.

    1.1 you can do this with this site: http://inloop.github.io/svg2android/ but it does not support all the features of SVG like some gradients.

    1.2 you can convert via android studio but it might use some features that only supports API 24 and higher that cuase crashe your app in older devices.

    and add vectorDrawables.useSupportLibrary = true in gradle file and use like this:

    
    
    1. use this library https://github.com/MegatronKing/SVG-Android that supports these features : https://github.com/MegatronKing/SVG-Android/blob/master/support_doc.md

    add this code in application class:

    public void onCreate() {
        SVGLoader.load(this)
    }
    

    and use the SVG like this :

    
    

提交回复
热议问题