Is there a way to tell if the soft-keyboard is shown?

You can detect the state AND coordinates of the software keyboard, using dumpsys shell command.

Because dumpsys requires permission.android.DUMP, which is a system application permission, you have two options: 1. use a rooted device to grant this permission. 2. override the problem using adb as described in my other answer.

Now, run the following command: dumpsys window InputMethod | grep "mHasSurface" to get the data you are looking for.


According to this POST

You cannot detect if soft keyboard is shown or not, but you can indirectly know that a soft key board is shown by knowing that the View of your activity is resized.

Imagine you have a ListView and at the bottom an EditText, you want to go to the bottom of the list when a soft keyboard is shown after user clicks the EditText.

You need to implement a subclass of ListView, then use it in your ListActivity or Activity or View.

public class ThreadView extends ListView {

    public ThreadView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
    }

    @Override
    protected void onSizeChanged(int xNew, int yNew, int xOld, int yOld) {
        super.onSizeChanged(xNew, yNew, xOld, yOld);

        if (yOld > yNew) {
            setSelection(((ListAdapter) getAdapter()).getCount() - 1);
        }
    }
}

Hope this helps

PS. "check Configuration Changes" only works for hand keyboard.

Tags:

Android