Skip to content

Instantly share code, notes, and snippets.

@johnkil
Created July 19, 2012 17:23
Show Gist options
  • Save johnkil/3145466 to your computer and use it in GitHub Desktop.
Save johnkil/3145466 to your computer and use it in GitHub Desktop.
The methods that opens and closes the keyboard
/**
* Shows the keyboard.
*
* @param view
*/
public void showKeyboard(View view) {
Context context = view.getContext();
InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
}
/**
* Hides the keyboard.
*
* @param view
*/
public void hideKeyboard(View view) {
Context context = view.getContext();
InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment