简体   繁体   English

如何禁用Android键盘的箭头键

[英]how to disable the arrow keys of android keyboard

im displaying web page content in webview and i want to disable the all 4 arrow key of android keyboard. 我在webview中显示网页内容,我想禁用Android键盘的所有4个箭头键。 any idea? 任何想法?

edit: 编辑:

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;
      }

    }

scrolling still there but back key and menu key is disabled why? 仍在滚动,但是后退键和菜单键被禁用了,为什么? i noticed it returns nothing if content is scrolling. 我发现如果内容正在滚动,它什么也不会返回。 once scrolling ends it(log.d message) returns 0. 一旦滚动结束,它(log.d消息)将返回0。

You can catch them in an onkeydown? 您可以在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);
  }
}

You'd only have to find the code for the arrow-keys, that shouldn't be to hard. 您只需要找到箭头键的代码,这并不难。 You could even just Log.d your event.getAction() , and press them, to find out what they're called... 您甚至可以Log.d您的event.getAction() ,然后按它们,以找出它们的名称...

I don't really know what you are doing with your debugcode, but check out this link: http://developer.android.com/reference/android/view/KeyEvent.html for the key events. 我真的不知道您在使用调试代码做什么,但是请查看此链接: http : //developer.android.com/reference/android/view/KeyEvent.html了解主要事件。 The events are integers. 事件是整数。 Why don't you add this for debugging: 您为什么不添加此内容以进行调试:

public boolean onKeyDown(int keyCode, KeyEvent event) {
    Log.d("yourTag",""+event.getAction());
}

and see what's returned? 看看返回了什么? My guess would be one of the DPAD keys, for instance left ( 21 ) are your target 我的猜测是DPAD键之一,例如,左(21)是您的目标

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM