.svg file as object in HTML not displayed in Android WebVIew

雨燕双飞 提交于 2019-12-08 02:03:59

问题


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>


来源:https://stackoverflow.com/questions/26386159/svg-file-as-object-in-html-not-displayed-in-android-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!