我在WebView中加载了url但是,当用户单击某个按钮时,新的url会加载到android浏览器中而不是我的webview中.我该怎么办?
提前致谢.
您必须同时使用WebViewClient和WebChromeClient.
例如,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(); } });