在Android的SVG支持Android、SVG

2023-09-12 10:32:16 作者:戒你比戒烟难

我们将开发一个Android应用程序用于显示一个AutoCAD的 绘制在ECMA脚本使用SVG格式文件。我们有 在测试模拟器中的应用,打开web视图中的SVG文件。 我们的问题是,ECMAScript中的XML标签没有在web视图执行 在机器人。我们知道Android从3.0只支持SVG。是否 它不支持的ECMAScript在SVG?

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?

在此先感谢

        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 石埠

Ragards Shibu

推荐答案

的Andr​​oid(3.0及更高版本)支持SVG与ECMAScript的。

Android (3.0 and later) supports SVG with ECMAScript.

问题是,不执行ecmacript在SVG时,SVG在&LT增加; IMG&GT; 标记。我还测试了几种桌面浏览器,当SVG是&LT; IMG&GT; 标签,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.

有5种方法如何添加SVG在HTML:

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

添加它作为与图像的&LT; IMG&GT; 标记 在与嵌入的&LT;嵌入&GT; 标记 在与嵌入的&LT; IFRAME&GT; 标记 在与嵌入的&LT;对象&gt; 标记 在嵌入SVG code直接到HTML(使用&LT; SVG&GT; 标签) Add it as an image with the <img> tag Embed it with the <embed> tag Embed it with the <iframe> tag Embed it with the <object> tag Embed svg code directly into the html (using <svg> tag)

在SVG ECMAScript的只执行,如果SVG嵌入&LT;嵌入&GT; &LT; IFRAME&GT; &LT;对象&gt; 标记。当直接在embeding SVG code &LT; SVG&GT; 标签,可能需要做一些code的变化(例如,在HTML的其他地方移动的脚本)的,但它也应该工作。

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.