2
There is some event or method that shows if the keyboard is active on the android screen, because I need to do this check in a Fragment.
2
There is some event or method that shows if the keyboard is active on the android screen, because I need to do this check in a Fragment.
1
Hello,
I found these 2 codes in SOEN
Mode 1
InputMethodManager imm = (InputMethodManager) getActivity()
.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm.isAcceptingText()) {
writeToLog("Software Keyboard was shown");
} else {
writeToLog("Software Keyboard was not shown");
}
Mode 2
contentView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
contentView.getWindowVisibleDisplayFrame(r);
int screenHeight = contentView.getRootView().getHeight();
// r.bottom is the position above soft keypad or device button.
// if keypad is shown, the r.bottom is smaller than that before.
int keypadHeight = screenHeight - r.bottom;
Log.d(TAG, "keypadHeight = " + keypadHeight);
if (keypadHeight > screenHeight * 0.15) { // 0.15 ratio is perhaps enough to determine keypad height.
// keyboard is opened
}
else {
// keyboard is closed
}
}
});
Right, but how do I make a loop to keep doing this check?
Browser other questions tagged java android mobile android-fragment
You are not signed in. Login or sign up in order to post.
You mean if the keyboard is being shown to the user?
– rsicarelli