2012-05-15 71 views
0

最近我正在爲Android 2.2開發一款應用程序。我在android 4.0上使用相同的應用程序但是,webview不顯示圖像,只顯示一個白色屏幕。Webview不顯示android 4.0中的圖像?

我剛纔用簡單的代碼:

WebView mWebView2 = (WebView) findViewById(R.id.webViewQ2); 
mWebView2.getSettings().setBuiltInZoomControls(true); 
mWebView2.getSettings().setJavaScriptEnabled(true); 
mWebView1.loadDataWithBaseURL("","<table width=\"100%\"><tr><td style=\"text-align:center; background-color:#c8c8c8;\">Question</td></tr></table>"+answer1, "text/html", "utf-8", ""); 
mWebView2.loadDataWithBaseURL("","<table width=\"100%\"><tr><td style=\"text-align:center; background-color:#c8c8c8;\">Question</td></tr></table>"+answer2, "text/html", "utf-8", ""); 

任何人都可以幫我請我的代碼是工作的罰款,但是這一點。

注意:它有時會自動顯示圖像,有時不顯示任何東西。

+0

你試過給它正確格式化的HTML嗎?即,添加''和''標籤。 –

+0

你把圖像? – MAC

+0

我想,如果HTML是在Android 2.2做工不錯,那麼它必須是確定運行 – Navdroid

回答

0

如果您確定您的HTML格式不正確,則可以嘗試在WebView上禁用硬件加速。

As explained here,請嘗試以下操作:在你的代碼

WebView mWebView2 = (WebView) findViewById(R.id.webViewQ2); 
myWebView2.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 
+0

setLayerType不能得到解決的錯誤! – Navdroid

+0

你的目標是什麼API級別? –

+0

Android 4.0.3。 – Navdroid

1
String htmlContent="<body style="+"text-align:center;"+"><img src=\""+url+"\"/></body>"; 
mywebview.loadDataWithBaseURL("not_needed", htmlContent, "text/html", "utf-8", "not_needed"); 

使用此。它爲我工作。