1
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, "");

链接后,我想要显示图像。那么如果该图像存储在sdcard的文件夹中,如何放置该图像的地址,/images即属性中的地址应该是什么src

问候

4

2 回答 2

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", "");  
于 2012-12-21T14:43:42.090 回答
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", "");
于 2012-12-21T14:47:03.183 回答