我有一个 Android 应用程序,它主要是一个显示本地文件的 WebView 的包装器。
WebView 获取事件是因为 setContentView(thewebview) 被调用。大多数情况下这都可以正常工作(因为我们还在在线版本中处理 Android Webkit 浏览器)。
问题是我想添加对方向键/轨迹球事件的支持。我已经编写了适当的 onKeyDown,但 WebView 正在消耗事件,而不是活动。
这可以通过两种方式解决:
- 处理方向键向下/向上等的事件键码。在 Javascript onKeyDown 函数中
- 获取并消费相应的按键事件,然后 webview 才能获取它们。 (当然,所有事件都可以获得,大多数事件根本不会被消耗)
问题是我也不知道该怎么做。我该如何做到这一点或以不同的方式解决这个问题?
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:
- Handle the event keycode for D-Pad Down/Up/etc. in the Javascript onKeyDown function
- Get and consume the appropriate key events before the webview can get them. (ofcourse also all events can be gotten, most will simply not be consumed)
Problem is I don't know how to do either. How can I do this or solve this in a different way?
发布评论
评论(1)
只需使用 View.setOnKeyListener() 来处理 KeyEvents。
在您的示例中,将像这样使用:
Simply 'catch' the keypresses on the WebView by using View.setOnKeyListener() to handle the KeyEvents.
In your example that would be used like this: