Detect keyboard in android

ぐ巨炮叔叔 提交于 2019-12-23 05:15:38

问题


I have an android application which contain list of installed applications and launch them on item click.In my application I used Intent.ACTION_CLOSE_SYSTEM_DIALOG broadcast for closing system dialogs such as Task Manager(Recent Apps dialog),Power Option dialog,Low battery dialog etc....But this hides keyboard in some devices.I want to make sure that the user could not interact with recent apps dialog from my applications.How can i close system dialogs except keyboard?How can i check whether the keyboard visible or not?Is it possible to detect Recent Apps dialog?I am stuck on this for hours.Any help must appreciating.


回答1:


I've used this code to detect keyboard.

view.getViewTreeObserver().addOnGlobalLayoutListener(
                new OnGlobalLayoutListener() {

                    @Override
                    public void onGlobalLayout() {


                            int heightDiff = 

view.getRootView().getHeight()
                                    - view.getHeight();
                            if (heightDiff > 200) {
                                keyboardUp = true;

                                return;
                            }
                            if (keyboardUp) {
                                keyboardUp = false;

                            }
                            Log.e("Keyboard", "" + keyboardUp);
                        }
                    });


来源:https://stackoverflow.com/questions/16102576/detect-keyboard-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!