2016-11-04 17 views
2

我想加上-接收時沒有達到過的網站錯誤或離線圖片「html/text」Andrioid webview?沒有任何的html文件

所以在這裏它的做工精細....在這裏我想添加一個圖像

但畫面不展示形式的資產文件夾

這是我的代碼

@SuppressWarnings("deprecation") 
public class Callback extends WebViewClient{ 
    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl){ 

     String html = "<div><p>&nbsp;<img style=\"display: block; margin-left: auto; margin-right: auto;\" src=\"file:///android_asset/img/error.png\" alt=\"\" width=\"218\" height=\"218\" /></p></div><div><p style=\"color: black; font-size: 20px; text-align: left;\"><strong><span style=\"color: #808080;\">Oops, Unable to load information.</span></strong></p><div style=\"color: black; text-align: center;\"><span style=\"color: #ff99cc;\"><strong>Please check your Network connection.</strong></span></div><br /><div><p style=\"color: black; text-align: center;\"><strong>Or</strong><br /><br /></p><div style=\"color: black; text-align: center;\"><span style=\"color: #666699;\"><strong>Server May be Temporarily Down</strong></span></div><div style=\"color: black; text-align: center;\"><div style=\"color: black; text-align: center;\"><span style=\"color: #666699;\"><strong>Please Try After Sometime</strong></span></div></div></div></div>"; 

     webView.getSettings().setJavaScriptEnabled(true); 
     webView.loadData(html, "text/html", "UTF-8"); 

    } 
} 
+0

\「file:///android_asset/img/error.png \\\」爲什麼在文件名後需要額外的'\'? –

+0

是的,沒有顯示錯誤 –

回答

2

檢查這個代碼是爲我工作,

webView.loadDataWithBaseURL(null,html, "text/html", "UTF-8",null); 
+0

謝謝它的工作Upvote我的問題 –

相關問題