OnUnhandledKeyEventListener

436 阅读1分钟
    /**
     * Interface definition for a callback to be invoked when a hardware key event hasn't
     * been handled by the view hierarchy.
     */
    public interface OnUnhandledKeyEventListener {
        /**
         * Called when a hardware key is dispatched to a view after being unhandled during normal
         * {@link KeyEvent} dispatch.
         *
         * @param v The view the key has been dispatched to.
         * @param event The KeyEvent object containing information about the event.
         * @return {@code true} if the listener has consumed the event, {@code false} otherwise.
         */
        boolean onUnhandledKeyEvent(View v, KeyEvent event);
    }
    

compileSdkVersion(30) > device version(24) 时候出现 OnUnhandledKeyEventListener class not found.

hardware keyevent 是啥意思? 字面理解是硬件按键。实体键盘,电源,音量。

视图层级没有处理硬件按键事件时,调用该类处理。看onUnhandleKeyEvent(View v, KeyEvent event)方法,里面的Key Event对应的键盘按键。

如何触发?

实体键事件传递到当前视图,视图没有处理实体键事件时调用。

误区:一直以为有KeyEvent$ACTION_MOVE这么一个常量。