.svg file as object in HTML not displayed in Andro

2019-07-19 23:08发布

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?

2条回答
聊天终结者
2楼-- · 2019-07-19 23:29

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>
查看更多
男人必须洒脱
3楼-- · 2019-07-19 23:33

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","");
查看更多
登录 后发表回答