Skip to content

Instantly share code, notes, and snippets.

@fpillet
Created February 9, 2012 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fpillet/1779575 to your computer and use it in GitHub Desktop.
Save fpillet/1779575 to your computer and use it in GitHub Desktop.
Detect whether the Android Soft Keyboard is up
containerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
{
public void onGlobalLayout()
{
final Activity app = getActivity();
if (app == null)
return;
Rect r = new Rect();
containerView.getWindowVisibleDisplayFrame(r);
boolean visible = (Math.abs(r.height() - containerView.getHeight()) > 128);
if (visible != keyboardVisible)
{
keyboardVisible = visible;
NotificationCenter.postNotification(
Constants.KEYBOARD_VISIBILITY_CHANGED,
this,
CFDictionary.withObjectsAndKeys(visible, "visible"));
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment