对SVG渲染Android的web视图支持 [英] Android webView support for svg rendering
问题描述
我有开发了Android 4.03的应用程序 - API 15级。它有一个web视图,我想用它来显示一个HTML页面的一些SVG内容。一些SVG内容直接内嵌到HTML,有些是使用JavaScript动态呈现。
I have an app which is developed with android 4.03 - API Level 15. It has a webView which i want to use to show an html page with some svg content. Some svg content are directly embeded to html and some are dynamically rendered using javascript.
我有一个与Android 2.2运行的华为S7平板电脑。我添加了一个向后兼容包,这样我就可以在该选项卡中运行我的应用程序。
I have a huawei S7 tablet which runs with android 2.2. I have added a backward compatibility pack so i can run my app in the tab.
现在,当我创建的HTML页面,并在dektop浏览器中运行它,它完美地呈现所有的SVG conent。 当我运行在平板电脑上的应用程序,它不显示任何SVG内容。它只是显示一个白色背景。 但是,当我尝试相同的应用程序在我的朋友们承上启下7平板电脑采用Android 4.3它完美地显示在web视图的所有SVG内容。
Now when i create the html page and run it in the dektop browser it perfectly renders all the svg conent. When i run the app in the tablet it doesn't show any svg content. It just displays a white background. But when i try the same app in my friends nexus 7 tablet with android 4.3 it perfectly shows all the svg content in the webView.
我用这个code初始化web视图
I use this code to initialize the webView
WebView mapView;
mapView = (WebView) findViewById(R.id.mapview);
mapView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
}
});
WebSettings s = mapView.getSettings();
s.setLoadWithOverviewMode(true);
s.setLoadsImagesAutomatically(true);
s.setUseWideViewPort(true);
s.setJavaScriptEnabled(true);
s.setSupportZoom(true);
s.setBuiltInZoomControls(true);
File externalStorage = Environment.getExternalStorageDirectory();
String url = "file:///" + externalStorage + "/floor_one.html";
mapView.loadUrl(url);
有没有在Android 2.2的web视图与SVG任何兼容性问题?
Is there any compatibility issue in android 2.2 webView with SVG ?
推荐答案
不支持的Android 3.0之前SVG,所以你必须找到一些解决办法。
SVG was not supported before Android 3.0, so you have to find some workaround.
本博客文章解释了两个JavaScript polyfills对SVG的。
This blog post explains two of Javascript polyfills for SVG.
<一个href="http://www.kendoui.com/blogs/teamblog/posts/12-02-17/using_svg_on_android_2_x_and_kendo_ui_dataviz.aspx" rel="nofollow">http://www.kendoui.com/blogs/teamblog/posts/12-02-17/using_svg_on_android_2_x_and_kendo_ui_dataviz.aspx
这篇关于对SVG渲染Android的web视图支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!