Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG support on Android

Tags:

android

svg

Does Android support SVG? any example?

like image 779
Kakey Avatar asked Oct 08 '10 11:10

Kakey


People also ask

Is SVG supported in Android?

Android Studio includes a tool called Vector Asset Studio that helps you add material icons and import Scalable Vector Graphic (SVG) and Adobe Photoshop Document (PSD) files into your project as vector drawable resources.

Which is better SVG or PNG for Android?

You will still need PNG images for older platforms, so the ideal workflow is to have vector-based source images that you export to PNG for various DPI buckets and convert to VectorDrawable format for API 21 devices using a project like svg2android.

Where do SVG files go Android Studio?

You can import an SVG file as a VectorDrawable in Android Studio, follow these steps : "Right-click" on the res folder and select new > Vector Asset. Select the Local File option and browse to your . svg file.


2 Answers

The most complete answer is this:

  • The Android 2.x default browser does not natively support SVG.
  • The Android 3+ default browsers DO support SVG.

To add SVG support to 2.x versions of the platform, you have two basic choices:

  1. Install a more capable browser (like Firefox or Opera Mobile - both support SVG)
  2. Use a JavaScript polyfill that can parse SVG and render it to an HTML5 canvas

The first option is okay if you're just trying to make SVG work for personal uses or a limited (controllable) set of users. It's not a great option if you want to use SVG while targeting a large, uncontrolled user base.

In the later case, you want to use a polyfill. There are many JavaScript libraries available today that can prase SVG and render to a canvas. Two examples are:

  • canvg
  • fabric.js

Using a polyfill, you can render your SVG in a canavs on all versions of Android 2.x.

For a more complete example of this approach, you can refer to this blog post that discusses the use of the canvg polyfill for making Kendo UI DataViz charts (SVG-based) work on Android 2.x. Hope that helps!

like image 82
Todd Avatar answered Oct 04 '22 20:10

Todd


There is a new open-source library that supports loading and drawing SVG Basic 1.1 files: https://github.com/pents90/svg-android. Performance is good as the actual drawing is handled natively by an android.graphics.Picture object.

like image 41
pents90 Avatar answered Oct 04 '22 20:10

pents90