.svg file as object in HTML not displayed in Andro

2019-07-19 22:51发布

问题:

My app has a WebView control that is able to load .svg files: when the url is a .svg file it is correctly displayed.

I modified the code not to load directly the .svg file so that I have to call something like

webView.loadDataWithBaseURL(baseUrl,"<html><body><object data='cover.svg'></object></body></html>","text/html", "UTF-8","");
  • The above mentioned code works with images but not with svg files.

  • An HTML file with the HTML parameter string above mentioned as HTML code is correctly displayed in Firefox (under Linux) with its svg object.

  • The object is always loaded with a WebView/browser-compatible file.

  • I want my code to be able to handle every kind of WebView/browser-compatible file that can be placed in an object.

What's wrong with my code?

回答1:

This worked with various formats:

webView.loadDataWithBaseURL(baseUrl,"<html><body><object onload='event.target.style.minWidth=screen.width;event.target.style.minHeight=screen.height;' data='cover.svg'></object></body></html>","text/html", "UTF-8","");


回答2:

To add SVG using the object element, write markup such as the following link

http://alistapart.com/article/using-svg-for-flexible-scalable-and-fun-backgrounds-part-ii

  <object type="image/svg+xml" 
    width="100" height="100" style="float:right" 
    data="http://blog.codedread.com/clipart/apple.svgz">
  <span/></object>