0

How to find event for softkeyboard visible or invisible. I want to catch event when keyboard gets appears and onback press it disappears. I am able catch event for Done button press and it works fine.

Any help appreciated. Thanks in advance.

Roshni
  • 61
  • 7
  • 1
    Refer to this http://stackoverflow.com/questions/2150078/how-to-check-visibility-of-software-keyboard-in-android and http://stackoverflow.com/questions/4745988/how-do-i-detect-if-software-keyboard-is-visible-on-android-device – Jitender Dev Oct 24 '13 at 09:53

1 Answers1

1
final View activityRootView = rellayLoginParent;
        activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener()
            {
                @Override
                public void onGlobalLayout()
                    {
                        Rect r = new Rect();
                        // r will be populated with the coordinates of your view that area still visible.
                        activityRootView.getWindowVisibleDisplayFrame(r);

                        int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
                        //MyLog.w("height difference is", "" + heightDiff);
                        if (heightDiff > 100)
                            { // if more than 100 pixels, its probably a keyboard...
                                /*isKeyBoardVisible = false;
                                linlayAdLayout.setVisibility(View.GONE);*/
                                Log.e("Keyboard Visibilitty","Visible");
                                if(lytAppHeader.getVisibility() == View.VISIBLE)
                                    {
                                        lytAppHeader.setVisibility(View.GONE);
                                    }
                            }
                        else
                            {
                                //linlayAdLayout.setVisibility(View.VISIBLE);
                                Log.e("Keyboard Visibilitty","InVisible + Gone");
                                if(lytAppHeader.getVisibility() == View.GONE)
                                    {
                                        lytAppHeader.setVisibility(View.VISIBLE);
                                    }
                            }

                    }
            });
Roshni
  • 61
  • 7