I have an app in which I have a WebView
where I display some websites. It works, clicking a link in the webpage goes to the next page in the website inside my a
I use something like this in my activities with WebViews:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
if (mWebView.canGoBack()) {
mWebView.goBack();
} else {
finish();
}
return true;
}
}
return super.onKeyDown(keyCode, event);
}
Edit:
For this code to work, you need to add a field to the Activity
containing the WebView:
private WebView mWebView;
Initialize it in the onCreate()
method and you should be good to go.
mWebView = (WebView) findViewById(R.id.webView);