Regarding this question and this question , if you use onKeyDown and onKeyLongPress, you need to use event.startTracking(); inside onKeyDown. But I use WebViews.
What can I do to join KeyDown and onKeyPress without losing the WebView return function?
I need this behavior:
Inside webview,
* When the user clicks the back button, the web view will return to history
* When the user long presses the return button, finish() will be called
public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { if(mWebView.canGoBack()) { mWebView.goBack(); } else { super.onBackPressed(); } return true; } return super.onKeyDown(keyCode, event); } @Override public boolean onKeyLongPress(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { finish(); return true; } return super.onKeyLongPress(keyCode, event); }
android webview onkeydown
trante
source share