Listener for EditText focus on the whole system

166 Views Asked by At

I need to know when to show a Notification that behaves similarly to the "Change input method" shown by the OS when an EditText is focused, so it can't be limited to EditTexts in my application.

Is there a way to do it? Some Listener or Intent? Where should I look in the source code to study how the OS does that?

1

There are 1 best solutions below

2
On

Do as following

LinearLayout mainLayout;

mainLayout = (LinearLayout) findViewById(R.id.mian_layout);

        mainLayout.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {

                Rect r = new Rect();
                mainLayout.getWindowVisibleDisplayFrame(r);


                int heightDiff = mainLayout.getRootView().getHeight() - (r.bottom - r.top);
                if (heightDiff > 100) {
                    // keyboard is open.
                } else {
                    //keyboard is closed.
                }
            }
        });