简体   繁体   中英

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. Some svg content are directly embeded to html and some are dynamically rendered using javascript.

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.

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.

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);

Is there any compatibility issue in android 2.2 webView with SVG ?

SVG was not supported before Android 3.0, so you have to find some workaround.

This blog post explains two of Javascript polyfills for SVG.

http://www.kendoui.com/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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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