Android SVG Support

We are going to develop an Android application to show an autocad drawing file in svg format, which uses an ecma script. We have tested the application in the emulator and opened the svg file in webview. our problem is that ecmascript in XML tags is not running in webview in android. We know that android only supports SVG from 3.0. 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

+6
source share
1 answer

Android (3.0 and later) supports SVG with ECMAScript.

The problem is that ecmacript in svg fails when svg is added to the <img> . I also tested it in several desktop browsers, and when svg is in the <img> , ecmascript was not executed in any of them.

There are 5 ways to add svg to html:

  • Add it as an image with the <img>
  • Paste it with the <embed>
  • Paste it with an <iframe>
  • Paste it with the <object>
  • Embed svg code directly in html (using the <svg> )

A script in svg is only executed if svg is embedded in the <embed> , <iframe> or <object> tags. When embedding svg code directly in the <svg> may need to make some code changes (for example, moving scripts elsewhere in html), but it should also work.

+11
source

Source: https://habr.com/ru/post/892667/


All Articles