如何设置WebChromeClient以在同一视图中打开新页面?

Ili*_*ija 11 android

我在WebView中加载了url但是,当用户单击某个按钮时,新的url会加载到android浏览器中而不是我的webview中.我该怎么办?

提前致谢.

Ben*_*tte 20

您必须同时使用WebViewClientWebChromeClient.

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

从WebView页面doc:

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();
   }
 });
Run Code Online (Sandbox Code Playgroud)


Sum*_*ant -3

只是通过

http://developer.android.com/reference/android/webkit/WebView.html

您将了解如何使用 webchromeClient......

告诉我这对你是否有帮助......