如果直接继承View类,然后override掉onKeyUp或者其它按键事件,会发现按键后并没有触发这个View派生类的onKeyUp事件,触发的是Activity的事件。“You will get key events only if your view is focusable and is focused. In the case of a game, you can set your view to be focusable in touch mode to get the key events pretty much automatically. ” 验证了一下,确实isFocusable是false的。调用一下setFocusable(true)或者setFocusableInTouchMode(true)就可以捕获按键事件了。
继承View类后onKeyUp无法触发
最新推荐文章于 2021-05-29 02:13:42 发布