在Android P中:由于没有窗口焦点而发生了dropping事件:KeyEvent [英] In Android P: Dropping event due to no window focus: KeyEvent
问题描述
在Android P
中,启动时应用程序无法正常运行,并抛出警告:
In Android P
, application on start not working as expected with throwing warnings :
W/ViewRootImpl:
Dropping event due to no window focus: MotionEvent { action=ACTION_DOWN, KeyCode = DPAD_DOWN}
和
W/ViewRootImpl: Cancelling event due to no window focus: MotionEvent { action=ACTION_UP, KeyCode = DPAD_DOWN} and its not allowing any action to performed.
查看图片以获取详细警告.
Check Image for detailed warning.
注意:相同的应用程序在Android O
中运行正常,但是在Android P
中,有时PopupMenu
项目中缺少焦点,并且直到重新启动系统后才重新获得焦点.使用后
dispatchKeyEvent
并将动态焦点设置为视图,因为v.requestFocus();
该应用程序开始运行得不太好,但有时仍会观察到警告,感觉就像用户挂了系统.检查下面的代码片段以获取详细信息:
Note: Same Application is working fine in Android O
, but in Android P
, sometimes the focus is missing in PopupMenu
items and not getting back the focus until reboot the system. After using
dispatchKeyEvent
and setting dynamically focus to the view as v.requestFocus();
the application started working little better but still the warning is observed sometimes with feel like system hanged for a user. Check below code snippet for details:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
LogUtils.d(TAG, String.valueOf(event.getKeyCode()));
this.getWindow().getDecorView().setFocusable(true);
return super.dispatchKeyEvent(event);
}
我的问题是,如何动态地将丢失的焦点设置为 PopupMenu
和RecyclerView
,或者如何在Android P中运行的应用程序中克服这一点.
My Question is, how to set the missing focus dynamically to the PopupMenu
and RecyclerView
or how to overcome this in application running in Android P.
请提出建议,我在stackOverflow中遇到了相同类型的问题,但没有适当的解决方案,因此请发布问题并等待所有类型的建议和答案. 在此先感谢.
Please suggest, I got same type of question in stackOverflow but not a proper solution, so posting the question and waiting for all type of suggestion and answer. Thanks in advance.
推荐答案
在我的情况下,类似的问题是由于在各处使用onKeyDown()和KeyEvent.ACTION_DOWN引起的,包括在按键时显示对话框时. 使用onKeyUp()和KeyEvent.ACTION_UP来显示对话框和活动可以为我解决该问题.
In my case similar issue was caused by using onKeyDown() and KeyEvent.ACTION_DOWN everywhere, including when showing a dialog on a key press. Using onKeyUp() and KeyEvent.ACTION_UP to show dialogs and activities resolved it for me.
这篇关于在Android P中:由于没有窗口焦点而发生了dropping事件:KeyEvent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!