我想阻止webview在从示例开始使用google.com时加载网址并返回默认网页[1。页]。
在我的webview客户端下面,它没有返回到第一页,因为应该覆盖方法的条件是好的。
public class myWebClient extends WebViewClient
{
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
// view.setVisibility(View.GONE);
rlChargement.setVisibility(View.VISIBLE);
progresswheel.spin();
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
// view.setVisibility(View.GONE);
System.out.println("BROWSER URL : "+url);
//Recherche sans filtre
if (url.equalsIgnoreCase("http://www.google.com")){
System.out.println("INVALID");
web.clearCache(true);
ActToast.message="error message";
startActivity(new Intent(me, ActToast.class));
rlChargement.setVisibility(View.GONE);
progresswheel.stopSpinning();
view.stopLoading();
web.clearHistory();
}
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
// animate(view);
// view.setVisibility(View.VISIBLE);
rlChargement.setVisibility(View.GONE);
progresswheel.stopSpinning();
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
web.loadUrl("file:///android_asset/onreceivingerror.html");
}
}
答案 0 :(得分:1)
您可能想要覆盖WebView.goBack():
@Override
public void goBack() {
WebBackForwardList temp = copyBackForwardList();
for (int i=0; i<temp.getSize(); i++) {
WebHistoryItem item = temp.getItemAtIndex(i);
// do whatever you want here...
}
// do whatever you want here...
super.goBack();
}