简体   繁体   English

Android webView支持svg渲染

[英]Android webView support for svg rendering

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. 我有一个用android 4.03 - API Level 15开发的应用程序。它有一个webView,我想用它来显示带有一些svg内容的html页面。 Some svg content are directly embeded to html and some are dynamically rendered using javascript. 一些svg内容直接嵌入到html中,一些内容是使用javascript动态呈现的。

I have a huawei S7 tablet which runs with android 2.2. 我有一个与Android 2.2一起运行的华为S7平板电脑。 I have added a backward compatibility pack so i can run my app in the tab. 我添加了一个向后兼容包,以便我可以在选项卡中运行我的应用程序。

Now when i create the html page and run it in the dektop browser it perfectly renders all the svg conent. 现在,当我创建html页面并在dektop浏览器中运行它时,它完美呈现所有svg conent。 When i run the app in the tablet it doesn't show any svg content. 当我在平板电脑上运行应用程序时,它不会显示任何svg内容。 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. 但是,当我在我的朋友nexus 7平板电脑与Android 4.3中尝试相同的应用程序时,它完美地显示了webView中的所有svg内容。

I use this code to initialize the webView 我使用此代码初始化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);

Is there any compatibility issue in android 2.2 webView with SVG ? 在带有SVG的android 2.2 webView中是否存在任何兼容性问题?

SVG was not supported before Android 3.0, so you have to find some workaround. Android 3.0之前不支持SVG,因此您必须找到一些解决方法。

This blog post explains two of Javascript polyfills for SVG. 这篇博文解释了两个用于SVG的Javascript polyfill。

http://www.kendoui.com/blogs/teamblog/posts/12-02-17/using_svg_on_android_2_x_and_kendo_ui_dataviz.aspx http://www.kendoui.c​​om/blogs/teamblog/posts/12-02-17/using_svg_on_android_2_x_and_kendo_ui_dataviz.aspx

What if you add this: 如果你添加这个怎么办:

webView.getSettings().setPluginState(PluginState.ON);

The only parameter I can see that you dont have that might have an effect. 我可以看到你没有的唯一参数可能会产生影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM