Skip to content

Instantly share code, notes, and snippets.

@izmajlowiczl
Last active September 5, 2018 16:12
Show Gist options
  • Save izmajlowiczl/6540078 to your computer and use it in GitHub Desktop.
Save izmajlowiczl/6540078 to your computer and use it in GitHub Desktop.
[Android] WebView back button
// Handles back button inside WebView.
// When user clicks back button and web history is not empty shows previous page from history.
mWebView.setOnKeyListener( new View.OnKeyListener() {
@Override
public boolean onKey( View v, int keyCode, KeyEvent event ) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return false;
}
});
@sivaprakashsj
Copy link

It is not working, Please try to update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment