[英]How can I change the previous web page to my own if it did not load in WEB VIEW?
PS我的英語很糟糕,我在文字上有錯誤)))請見諒! 問題是,當加載新頁面時,WEBVIEW 顯示前一個頁面,如果根本沒有加載或加載錯誤,則會顯示消息 The web page is not available,我不想在所有,但隱藏或用我自己的替換它,這怎么可能實現? https://cloud.mail.ru/public/321U/4DU3gj9dy這是我的 Android Studio 項目。 存檔密碼:myapps123
要查找並查看錯誤,請重建項目並按照以下步驟操作:將應用程序安裝到您的手機/
您可以在 onReceivedError 函數中調用 loadErrorPage(view) 函數。
以下代碼將加載您需要顯示的錯誤內容。這里我使用 loadDataWithBaseURL 加載 html 文件。
public void loadErrorPage(WebView webview){
if(webview!=null){
String htmlData ="<html><body><div align=\"center\" >"This is
the description for the load fail : "+description+"\nThe failed url is
: "+failingUrl+"\n"</div></body>";
webview.loadUrl("about:blank");
webview.loadDataWithBaseURL(null,htmlData, "text/html", "UTF-8",null);
webview.invalidate();
}
}
你可以這樣寫 onReceivedError :
WebView wv = (WebView) findViewById(R.id.webView);
wv.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
suåper.onReceivedError(view, errorCode, description, failingUrl);
//call loadErrorPage function here
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.