Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
915 views
in Technique[技术] by (71.8m points)

webview - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...