Reputation: 14060
I've got an Android app which is mostly a wrapper around a WebView which show local files. The WebView gets the events because setContentView(thewebview) is called. This works fine most of the times (since we also handle Android Webkit Browser in the online version).
Problem is that I want to add support for D-Pad/Trackball events. I've written the appropriate onKeyDown's, but the WebView is consuming the events, not the activity.
This can be fixed in two ways:
Problem is I don't know how to do either. How can I do this or solve this in a different way?
Upvotes: 1
Views: 1777
Reputation: 5969
Simply 'catch' the keypresses on the WebView by using View.setOnKeyListener() to handle the KeyEvents.
public void setOnKeyListener (View.OnKeyListener l)
Register a callback to be invoked when a key is pressed in this view.
In your example that would be used like this:
thewebview.setOnKeyListener(new OnKeyListener()
{
@Override
public boolean onKey(View v, int keyCode, KeyEvent event)
{
// do your stuff here
}
});
Upvotes: 2