webView.setWebViewClient(new SelfWebViewClient());
public class SelfWebViewClient extends WebViewClient { @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); //加载结束 } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { super.onReceivedError(view, errorCode, description, failingUrl); //在此处显示加载失败页面 loadFailure.setVisibility(View.VISIBLE); } @Override public void onLoadResource(WebView view, String url) { super.onLoadResource(view, url); //加载资源 } @Override public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) { super.onReceivedHttpAuthRequest(view, handler, host, realm); //webview保存密码 } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); //开始加载页面 } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { //点击链接跳转,对网页中超链接按钮的响应。 view.loadUrl(url); return true } }
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) { webView.goBack(); //goBack()表示返回WebView的上一页面 return true; } else{ finish(); } return false; }
android WebView(三)WebViewClient
原文地址:http://blog.csdn.net/w2865673691/article/details/44944459