Here is a workaround that seems to do the trick for me:
First, create the following method and call it from your application's onCreate()
method:
private static final int KEYBOARD_HEIGHT_THRESHOLD = 150;
private static final int CHECK_KEYBOARD_DELAY = 200; //ms
private void addKeyboardListener() {
final View rootView = graphics.getView();
final Rect layoutChangeRect = new Rect();
rootView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(CHECK_KEYBOARD_DELAY);
} catch (InterruptedException e) {
e.printStackTrace();
}
rootView.getWindowVisibleDisplayFrame(layoutChangeRect);
if (Math.abs(rootView.getHeight() - layoutChangeRect.height()) < KEYBOARD_HEIGHT_THRESHOLD) {
//keyboard closed
} else {
//keyboard opened
}
}
}).start();
}
});
I have used arbitrary values for CHECK_KEYBOARD_DELAY
and KEYBOARD_HEIGHT_THRESHOLD
that work OK for me. These values seem necessary, since the keyboard is animated.
Hope this helps.