Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG support in Android

We are going to develop an android application for show a autocad drawing file in svg format in which ecma script is using. We have tested the application in emulator and opened the svg file in webview. our problem is that ecmascript in XML tags are not executed in webview in android. We know that android is supporting SVG from 3.0 only. Does it not support ecmascript in svg?

Thanks in advance

        final String mimeType = "text/html"; 
        final String encoding = "utf-8"; 
        final String html = "<p><img height=\"600px\" width=\"600px \"src=\"file:///android_asset/drawing3.svg\" /></p>"; 


        WebView wv = (WebView) findViewById(R.id.webview_component); 
        wv.getSettings().setJavaScriptEnabled(true); 
        wv.loadDataWithBaseURL("fake://not/needed", html, mimeType, encoding, ""); 

Ragards Shibu

like image 250
Shibu S R Avatar asked Jul 13 '11 10:07

Shibu S R


People also ask

Does SVG work on mobile?

The . svg image uploads correctly and displays correctly as a logo on desktop in any browser. The logo . svg does not display on android or iphone in any browser.

Can we use SVG for app icon Android?

If you want to use some icons that are not present in the list of predefined icons, then you can add your own icon by selecting the Asset Type as Local File(SVG, PSD) and then select the path of your file by clicking on Path. After that click on Next > Finish. Now your icon will be added to your res/drawable folder.

What does SVG support?

An SVG (scalable vector graphics) is an XML-based vector image format for two-dimensional graphics with support for interactivity and animation. The SVG specification is an open standard developed by the World Wide Web Consortium (W3C) since 1999. You can even manipulate SVG files with code or your text editor.


1 Answers

Android (3.0 and later) supports SVG with ECMAScript.

The problem is that ecmacript in svg isn't executed when svg is added in the <img> tag. I also tested it in several desktop browsers and when svg is in <img> tag, ecmascript wasn't executed in any of them.

There are 5 ways how to add svg in the html:

  1. Add it as an image with the <img> tag
  2. Embed it with the <embed> tag
  3. Embed it with the <iframe> tag
  4. Embed it with the <object> tag
  5. Embed svg code directly into the html (using <svg> tag)

The ecmascript in the svg is executed only if the svg is embedded in <embed>, <iframe> or <object> tag. When embeding svg code directly in <svg> tag, it might be necessary to do some code changes (e.g. moving the scripts elsewhere in the html), but it should also work.

like image 151
Tomik Avatar answered Sep 21 '22 02:09

Tomik