使用音量键滚动 webView
如何使用音量硬键滚动 webView? ...可以通过缓动来完成吗?如果是这样,怎么办?我是 Android 新手 - 来自 ActionScript,任何帮助将不胜感激。
my R.id.webPg001 is a WebView id.
这就是我现在所处的位置:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int action = event.getAction();
int keyCode = event.getKeyCode();
ScrollView scrollView;
scrollView = (ScrollView) findViewById(R.id.webPg001);
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
if (action == KeyEvent.ACTION_UP) {
scrollView.pageScroll(ScrollView.FOCUS_UP);
scrollView.computeScroll();
}
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
if (action == KeyEvent.ACTION_UP) {
scrollView.pageScroll(ScrollView.FOCUS_DOWN);
scrollView.computeScroll();
}
return true;
default:
return super.dispatchKeyEvent(event);
}
}
How do you scroll a webView w/ the volume hard keys? ...and can it be done with easing? If so, how? I'm a nooB to Android - Coming over from ActionScript and any help will be greatly appreciated.
my R.id.webPg001 is a WebView id.
This is where I'm at now:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int action = event.getAction();
int keyCode = event.getKeyCode();
ScrollView scrollView;
scrollView = (ScrollView) findViewById(R.id.webPg001);
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
if (action == KeyEvent.ACTION_UP) {
scrollView.pageScroll(ScrollView.FOCUS_UP);
scrollView.computeScroll();
}
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
if (action == KeyEvent.ACTION_UP) {
scrollView.pageScroll(ScrollView.FOCUS_DOWN);
scrollView.computeScroll();
}
return true;
default:
return super.dispatchKeyEvent(event);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是正确的代码:(thnx NdrU!!)
Here is the correct code: (thnx NdrU!!)
WebView 有方法
pageUp
和pageDown
,根据 javadoc,它们滚动半页,因此您可能需要调用它们两次以获得整页滚动。至于您拥有的代码,我认为监听按钮按下的首选方法是覆盖
onKeyUp
和onKeyDown
方法,但我可能是错的(我是新手我自己开发android)。WebView has methods
pageUp
andpageDown
, according to the javadoc, they scroll half a page, so you will probably want to call them twice to get a full page scroll.As to the code you have, I thought the preffered way to listen to button presses is by overriding
onKeyUp
andonKeyDown
methods, but I might be wrong (I'm new to android development myself).以防万一您不知道,正常的导航机制是使用箭头键或轨迹球进行硬件级导航。您的网络视图应该插入到此机制中,而无需您付出任何额外的努力,因此,除非您有明确的应用程序特定原因需要点击音量键,否则我建议您使用此处的内置功能。
Just in case you're not aware, the normal mechanism for navigation is to use the arrow keys or trackball for hardware-level navigation. Your webviews should plug in to this mechanism with no additional effort on your part, and so unless you have a clear application-specific reason for tapping into the volume keys, I would recommend using the built-in functionality here.