Skip to content

Instantly share code, notes, and snippets.

@devrath
Created November 19, 2014 11:58
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 devrath/fd62e68c2bc2319a787a to your computer and use it in GitHub Desktop.
Save devrath/fd62e68c2bc2319a787a to your computer and use it in GitHub Desktop.
Hide the keyboard onClick of outside click of edit text
// REFER: http://stackoverflow.com/a/19828165/1083093
//Step1: Add in the root of the layout, if its a scrollview add to the parent(eg:linearlayout) not the scroll view
android:clickable="true"
android:focusableInTouchMode="true"
//Step2: Add this method
public void hideKeyboard(View view) {
InputMethodManager inputMethodManager =(InputMethodManager)getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
//Step3: Add this setOnFocusChangeListener event in onStart for the editText
edittext.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
hideKeyboard(v);
}
}
});
@binodappworks
Copy link

cbcvbcb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment