shouldOverrideUrlLoading

shouldOverrideUrlLoading

我试图使用shouldOverrideUrlLoading处理我的webview上的某些tel:链接,但出现此错误:

错误:方法未覆盖或从超类型实现方法

我该如何解决?

public class MainActivity extends AppCompatActivity {
        private WebView myWebView;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            myWebView = (WebView) findViewById(R.id.WebView);
            WebSettings webSettings = myWebView.getSettings();
            webSettings.setJavaScriptEnabled(true);
            myWebView.loadUrl("https://**************/");
            myWebView.setWebViewClient(new WebViewClient());
            final ProgressBar Pbar;
            Pbar = (ProgressBar) findViewById(R.id.pB1);
            myWebView.setWebChromeClient(new WebChromeClient() {

                public void onProgressChanged(WebView view, int progress)
                {
                    if(progress < 100 && Pbar.getVisibility() == ProgressBar.GONE){
                        Pbar.setVisibility(ProgressBar.VISIBLE);
                    }
                    Pbar.setProgress(progress);
                    if(progress == 100) {
                        Pbar.setVisibility(ProgressBar.GONE);
                        myWebView.requestFocus(View.FOCUS_DOWN);
                    }
                }
                @SuppressWarnings("deprecated")
                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    if (url.startsWith("tel:")) {
                        Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
                        startActivity(intent);
                        view.reload();
                        return true;
                    }

                    view.loadUrl(url);
                    return true;
                }
            });


        }




    }


覆盖显示为灰色,但我无法弄清楚如何修复它,我对Java不太熟悉,它使我发疯,请提前感谢!

最佳答案

这是因为您要覆盖的WebChromeClient中没有shouldOverrideUrlLoading。

您可以覆盖其中的WebChromeClient的shouldOverrideUrlLoading

10-04 18:24