在Android P中:由于没有窗口焦点而发生了dropping事件:KeyEvent [英] In Android P: Dropping event due to no window focus: KeyEvent

查看:1945
本文介绍了在Android P中:由于没有窗口焦点而发生了dropping事件: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);
        }

我的问题是,如何动态地将丢失的焦点设置为 PopupMenuRecyclerView,或者如何在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆