簡體   English   中英

如果沒有在 WEB VIEW 中加載,如何將以前的網頁更改為我自己的網頁?

[英]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

要查找並查看錯誤,請重建項目並按照以下步驟操作:將應用程序安裝到您的手機/

  1. 啟動應用程序。
  2. 打開頁面上的任何鏈接。
  3. 關閉互聯網,但不要最小化應用程序!
  4. 打開任何鏈接。
  5. 單擊重新加載兩次
  6. 打開互聯網,但不要最小化應用程序!(按住旅游設備中的主頁按鈕 :-)
  7. 使用防火牆阻止應用程序訪問 Internet。
  8. 單擊應用程序菜單欄中的房屋按鈕。 9.點擊屏幕。
  9. 單擊重新加載並查看錯誤 - 我想隱藏此錯誤或在我的屏幕或頁面上替換它。

您可以在 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM