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 becomes very annoying when the app has many icons or images.
Can anyone be as kind to give a step by step process of the simplest to use library for using SVG in Android, I'm sure this will help many others too.
Also I use Android Studio and Illustrator for generating my icons and images.
Ok after some hours of research I found svg-android to be quite easy to use, so I'm leaving here step by step instructions:
download lib from: https://code.google.com/p/svg-android/downloads/list Latest version at the moment of writing this is:
svg-android-1.1.jar
Put jar in
lib
dir.Save your *.svg file in
res/drawable
dir (In illustrator is as easy as pressing Save as and select svg)Code the following in your activity using the svg library:
You can reduce boilerplate code like this
Very easy I made a simple class to contain past code and reduce boilerplate code, like this:
Now I can call it like this in activity:
Try the SVG2VectorDrawable Plugin. Go to Preferences->Plugins->Browse Plugins and install SVG2VectorDrawable. Great for converting sag files to vector drawable. Once you have installed you will find an icon for this in the toolbar section just to the right of the help (?) icon.
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:add this code in application class:
and use the SVG like this :
First you need to import
svg
files by following simple steps.If image is available in your computer then select local
svg
file. After that select the image path and an option to change the size of the image is also available at the right side of dialog if you want to . in this waysvg
image is imported in your project After that for using this image use the same procedureAndroid Studio supports SVG from 1.4 onwards
Here is a video on how to import.
Rather than adding libraries which increases your apk size, I will suggest you to convert Svg to drawable using http://inloop.github.io/svg2android/ . and add
vectorDrawables.useSupportLibrary = true
in gradle,