2014-05-05 209 views
1

我無法在android webview中顯示圖像使用方法loadUrl(「http://www.zhihu.com/question/22091564/answer/25190954」); 。如何在android webview中加載圖像?

也許JS或CSS不加載我解決不了

像:

<img src="//s1.zhimg.com/misc/whitedot.jpg" data-rawwidth="1132" data-rawheight="659" class="origin_image zh-lightbox-thumb lazy" width="1132" data-original="http://p1.zhimg.com/85/dd/85dd508328e80af323a98e1d8e05db6a_r.jpg" data-actualsrc="http://p1.zhimg.com/85/dd/85dd508328e80af323a98e1d8e05db6a_m.jpg"> 

鏈接:http://www.zhihu.com/question/22091564/answer/25190954

回答

0

試試這個:

public class YourActivity extends Activity { 

private static final String HTML_FORMAT = "<html><body style=\"text-align: center; background-color: black; vertical-align: center;\"><img src = \"%s\" /></body></html>"; 
private WebView mWebView; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    mWebView = (WebView) findViewById(R.id.yourWebView); 

    final String imgUrl = "http://xxx.xxx"; 
    final String html = String.format(HTML_FORMAT, imgUrl); 

    mWebView.loadDataWithBaseURL("", html, "text/html", "UTF-8", ""); 
    //not required but cant help 
    mWebView.getSettings().setUseWideViewPort(false); 
    } 
} 
+0

我認爲js不加載 – niushu

+0

或css不加載 – niushu

+0

加這個: mWebView.getSettings()。setJavaScriptEnabled(true); – josedlujan

相關問題