Normally, we will have a Back button on browser, for user to go back in history. The default behaviour of the BACK button on Android system is Exiting the app. In order to change it's behaviour, we can override the onKeyDown() method: if it's BACK button pressed AND there has a back history item, than go back; otherwise pass to super method to handle as normal.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK){
if(webView.canGoBack()){
webView.goBack();
return true;
}
}
return super.onKeyDown(keyCode, event);
}
Related Post:
-
Display Progress Bar on WebView when loadingnext:
-
Load local HTML from /assetsrelated:
-
Create your own London 2012 App
No comments:
Post a Comment