Skip to content

Instantly share code, notes, and snippets.

@creativepsyco
Last active December 26, 2015 23:19
Show Gist options
  • Save creativepsyco/7229277 to your computer and use it in GitHub Desktop.
Save creativepsyco/7229277 to your computer and use it in GitHub Desktop.
Hide the keyboard from view
// Very useful to capture the focus if there is a need to
// Currently this hides the keyboard from the view
// If the underlying view is not an EditText
// For this to work all the parent layouts
// must declare themselves as focusableinTouchMode
// Focusable and clickable
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
View v = getActivity().getCurrentFocus();
boolean ret = super.dispatchTouchEvent(ev);
View w = getActivity().getCurrentFocus();
if (!(w instanceof EditText)) {
// Edit Text losing focus
// Hide the keyboard here or anything else that you wanna do.
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment