【发布时间】:2012-01-06 18:07:17
【问题描述】:
我已经在 sdcard 的根目录中下载了 map750.png 文件,但是当我尝试在带有一些文本的 web 视图中显示它时,只显示文本。你能帮我找出代码中的问题吗?谢谢。
setContentView(R.layout.webview);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setBuiltInZoomControls(true);
String html = "<html><head></head><body><p>hello</p><img src=\"file://mnt/sdcard/map750.png\" alt=\"alternativo\" /></body></html>";
mWebView.loadData(html, "text/html","utf-8");
我编辑帖子以添加oneilse14建议的解决方案,谢谢!!
setContentView(R.layout.webview);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setBuiltInZoomControls(true);
String html = "<html><head></head><body><p>hello</p><img src=\"file://mnt/sdcard/map750.png\" alt=\"alternativo\" /></body></html>";
mWebView.loadDataWithBaseURL("", html, "text/html", "utf-8", "");
【问题讨论】:
-
检查我的答案,它肯定会工作。
-
如何从 sdcard 加载 SVG 图像?
标签: android image webview sd-card