Difference between onKey(), OnKeyDown() and dispatchKeyEvent() methods provided by Android?

前端 未结 2 1111
醉话见心
醉话见心 2020-11-29 04:54

What is the difference between onKey(), OnKeyDown() and dispatchKeyEvent() methods provided by Android?
I Would like to know when and where each of these can be used.

2条回答
  •  野性不改
    2020-11-29 05:54

    DispatchKeyEvent Hardware key events are always delivered to the View currently in focus. They are dispatched starting from the top of the View hierarchy, and then down, until they reach the appropriate destination. If your View (or a child of your View) currently has focus, then you can see the event travel through the dispatchKeyEvent() method. In short, dispatchKeyEvent() will be only called if TextView/EditText is in focus.

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

提交回复
热议问题