我将URL加载到WebView中,但是,当用户单击某个按钮时,新的URL将加载到android浏览器中,而不是我的webview中。我应该怎么办?

提前致谢。

最佳答案

您必须同时使用 WebViewClient WebChromeClient

例如,WebChromeClient允许您获取加载进度,而WebViewClient则允许您覆盖 shouldOverrideUrlLoading ()。

从WebView页面文档中:

webview.setWebChromeClient(new WebChromeClient() {
   public void onProgressChanged(WebView view, int progress) {
     // Activities and WebViews measure progress with different scales.
     // The progress meter will automatically disappear when we reach 100%
     activity.setProgress(progress * 1000);
   }
 });
 webview.setWebViewClient(new WebViewClient() {
   public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
     Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
   }
 });

关于android - 如何设置WebChromeClient在同一 View 中打开新页面?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5104927/

10-12 03:57