我在 webview 中显示网页内容,我想禁用 android 键盘的所有 4 个箭头键。有什么想法吗?
编辑:
public boolean onKeyDown(int keyCode, KeyEvent event) {
int a;
Log.d("yourTag",""+event.getAction());
System.out.println(a=event.getAction());
System.out.println(keyCode);
if(event.getAction()==20){
return true;
}
else if(event.getAction()==21){
return true;
}
else if(event.getAction()==22){
return true;
}
else{
return true;
}
}
滚动仍然存在,但后退键和菜单键被禁用,为什么?我注意到如果内容正在滚动,它什么都不返回。一旦滚动结束,它(log.d 消息)返回 0。
最佳答案
您可以在 onkeydown 中捕获它们吗?
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(event.getAction() == /*INSERT YOUR KEY*/){
//do something with the arrows. or ignore them
//return true or false depending on if you want to "catch" the event i guess
}else{
return super.onKeyDown(keyCode, event);
}
}
您只需找到箭头键的代码,这应该不会太难。您甚至可以只记录您的 event.getAction()
,然后按它们,以找出它们的名称...
我真的不知道你在用你的调试代码做什么,但是看看这个链接:http://developer.android.com/reference/android/view/KeyEvent.html对于关键事件。事件是整数。为什么不添加这个进行调试:
public boolean onKeyDown(int keyCode, KeyEvent event) {
Log.d("yourTag",""+event.getAction());
}
看看返回了什么?我的猜测是 DPAD 之一键,例如 left ( 21 ) 是你的目标
关于android - 如何禁用android键盘的箭头键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5603975/