I'd like to get notified when the virtual keyboard is shown / dismissed. This does not seem to be possible, other than by using some layout resizing listener tricks:
How to check visibility of software keyboard in Android?
My activity has a single EditText. I could make it not have focus at activity startup, then add a focuschangelistener to it. When it gains focus, I can do my onVirtualKeyboardShown() stuff. If I could just listen for the back key being pressed in the EditText, I could then interpret that as the virtual keyboard being hidden. Something like:
EditText et = ...;
et.setOnFocusChangedListener(new OnFocusChangedListener() {
public void onFocusChanged(boolean focused) {
if (focused) {
// virtual keyboard probably showing.
}
}
});
et.setKeyListener(new KeyListener() {
public void onKeyPressed(int code) {
if (code == BACK_KEY) [
if (et.isFocused()) {
// virtual keyboard probably hiding.
// lose focus to set up for next time.
et.setFocused(false);
}
}
}
});
Seems like any approach is fraught with problems given all the differences between virtual keyboards, then we also have to deal with physical keyboards too,
Thanks