WebView wv = (WebView) findViewById(R.id.webview1);
wv.setWebViewClient(new Callback());
WebSettings webSettings = wv.getSettings();
webSettings.setBuiltInZoomControls(true);
final String mimeType = "text/html";
final String encoding = "UTF-8";
String html = "<H1>A simple HTML page</H1><body>" +"<a>link using anchor tag</a>"+
"<p>The quick brown fox jumps over the lazy dog</p>";
wv.loadDataWithBaseURL("", html, mimeType, encoding, "");
链接后,我想要显示图片。所以
如果该图像存储在SD卡的/images
文件夹中,该如何放置该图像的地址
即src
属性中的地址应该是什么?
问候
答案 0 :(得分:0)
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setBuiltInZoomControls(true);
String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
String imagePath = "file://"+ base + "/test.jpg";
String html = "<html><head></head><body><img src=\""+ imagePath + "\"></body></html>";
mWebView.loadDataWithBaseURL("", html, "text/html","utf-8", "");
答案 1 :(得分:0)
在imagePath中,设置图像的位置。像这里显示test.jpg文件存储在images文件夹中。
String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
String imagePath = "file://"+ base + "/images/test.jpg";
String html = "<html><head></head><body><img src=\""+ imagePath + "\"></body></html>";
mWebView.loadDataWithBaseURL("", html, "text/html","utf-8", "");