无法加载webview错误页面

时间:2017-08-26 11:20:29

标签: android webview

我执行此代码以在连接断开时加载错误页面。我正在尝试从assets文件夹加载文件但无法加载。拜托,有人来帮助我。 我在加载页面之前也显示了进度条。

 setContentView(R.layout.activity_main);
    frameLayout = (FrameLayout) findViewById(R.id.frameLayout);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    progressBar.setMax(100);
    webView = (WebView) findViewById(R.id.webView);
    webView.setWebViewClient(new HelpClient());
  /*  webView.setWebViewClient(new WebViewClient(){

        public void onReceivedError (WebView view, int errorCode, String description, String faillingUrl ){
            webView.loadUrl("file:///android_asset/Splash-LS.png");
        }
    });*/
    webView.setWebChromeClient(new WebChromeClient(){

        public void onProgressChanged(WebView view, int progress){
            frameLayout.setVisibility(View.VISIBLE);
            progressBar.setProgress(progress);
        setTitle("Chargement ...");
             if (progress == 100){
                 frameLayout.setVisibility(View.GONE);
                 setTitle(view.getTitle());
             }
                super.onProgressChanged(view, progress);


    }
       /* public void onReceivedError (WebView view, int errorCode, String description, String faillingUrl ){
            webView.loadUrl("file:///android_asset/Splash-LS.png");
        }*/
 });
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setVerticalScrollBarEnabled(false);
    webView.loadUrl(webAddress);
    progressBar.setProgress(0);

    webView.setWebViewClient(new WebViewClient(){
            public void onReceivedError (WebView view, int errorCode, String description, String faillingUrl ){
            webView.loadUrl("file:///android_assets/erreur.html");
        }
    });

    }

1 个答案:

答案 0 :(得分:0)

可能有几个原因,但很可能 - 您使用的是android_assets而不是android_asset

这应该是从资产加载html文件的正确行

webView.loadUrl("file:///android_asset/erreur.html");