android中onKeyDown解析

来源:互联网 发布:js 继承 编辑:程序博客网 时间:2024/05/16 04:39

boolean android.app.Activity.onKeyDown(int keyCode,KeyEvent event)

这个方法返回的是布尔值

public booleanonKeyDown(int keyCode, KeyEvent event)

Since: API Level 1

Called when a key was pressed down and not handled by any of the views inside of the activity.

当一个按键被按下时调用该方法并且不用处理这个activity内部的任何界面。

 So, for example, key presses while the cursor is inside a TextView will not trigger the event (unless it is a navigation to another object) because TextView handles its own key presses.

因此,例如,当光标停在一个TextView上面按键按下时不会触发这个事件(除非它是另一个对象的导航),因为TextView处理它自己的按键事件。

If the focused view didn't want this event, this method is called.

如果光标所在的视图不想这个事件,这个方法被调用。

The default implementation takes care of KEYCODE_BACK by callingonBackPressed(), though the behavior varies based on the application compatibility mode: forECLAIR or later applications, it will set up the dispatch to callonKeyUp(int, KeyEvent) where the action will be performed; for earlier applications, it will perform the action immediately in on-down, as those versions of the platform behaved.

默认通过调用onBackPressed()方法来负责实现KEYCODE_BACK,尽管行为变化基于应用程序的兼容模式:它将为ECLAIR或者更高版本的应用程序,在行动展现的地方设置调度去调用onKeyUp(int ,KeyEvent)方法;在更低的版本中,它将在按下按键之后立即展现这个动作,就像这些版本在这个平台上所展现的。

Other additional default key handling may be performed if configured withsetDefaultKeyMode(int).

其他另外的默认的按键如果用setDefaultKeyMode(int)方法配置,则它的处理可能会展现出来。

Parameters

参数

keyCode

The value in event.getKeyCode().

event.getKeyCode()方法中的值

event

Description of the key event.

按键事件的描述

Returns
  • Return true to prevent this event from being propagated further, orfalse to indicate that you have not handled this event and it should continue tobe propagated.

如果阻止这个事件传播则返回true,如果表明你没有处理这个事件并且它应该继续被传播时返回false。

See Also

看其他方法:

  • onKeyUp(int, KeyEvent)
  • KeyEvent