Android Studio-Webview API级别-29问题

时间:2019-06-20 10:51:43

标签: java android android-webview

当页面可见时,似乎android 29的webview正在调用onpagestarted,因此我无法像在<29中那样使页面可见之前使进度对话框显示。

webView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
        //onpage start
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            //if not first time show the second dialog or else dont show
            if (!firsttime) {
                loading2.setVisibility(View.VISIBLE);
            }
            else{
                loading2.setVisibility(View.INVISIBLE);
            }
            is_loading = true;

        }

        @Override
        public void onLoadResource(WebView view, String url) {
            super.onLoadResource(view, url);
        }

        @Override
        public void onPageCommitVisible(WebView view, String url) {
            super.onPageCommitVisible(view, url);
            //set loading false 
            is_loading = false;
            loading2.setVisibility(View.INVISIBLE);
        }

        public void onPageFinished(WebView view, String url) {
            //set loading false 
            is_loading = false;
            if (firsttime) {
                relativeLayout.setVisibility(View.INVISIBLE);
                firsttime = false;

            }
            loading2.setVisibility(View.INVISIBLE);
            webView.setVisibility(View.VISIBLE);
        }

        public void onReceivedError(WebView view, int errorCode, String description, final String failingUrl) {
            //if error recieve
            if (firsttime) {
                relativeLayout.setVisibility(View.INVISIBLE);
                firsttime = false;
            }
            loading2.setVisibility(View.INVISIBLE);
            view.setVisibility(View.GONE);
            webView.loadUrl("file:///android_asset/error.html");
            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
            builder.setTitle("Opss..")
                    .setMessage("Sorry, Please try Again !")
                    .setPositiveButton("Retry", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {

                            webView.loadUrl(failingUrl);
                            iserror = true;
                        }
                    })
                    .setCancelable(false)
                    .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            finish();
                        }
                    })
                    .show();
        }

    });

1 个答案:

答案 0 :(得分:0)

伙计们,我已经解决了这个问题。...我在页面覆盖中写了我的代码,它起作用了...