Skip to content

Instantly share code, notes, and snippets.

@yyunikov
Last active August 29, 2015 14:08
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 yyunikov/9adceac7e5c1de2f940e to your computer and use it in GitHub Desktop.
Save yyunikov/9adceac7e5c1de2f940e to your computer and use it in GitHub Desktop.
Android: some utilities for working with keyboard
public final class KeyboardUtils {
private KeyboardUtils(){}
public static void hideSoftKeyboard(final Activity activity)
{
final InputMethodManager imm = (InputMethodManager) activity.getSystemService(
Context.INPUT_METHOD_SERVICE);
if (activity.getWindow() != null && activity.getWindow().getCurrentFocus() != null) {
imm.hideSoftInputFromWindow(activity.getWindow().getCurrentFocus().getWindowToken(), 0);
}
}
public static void showSoftKeyboard(final Activity activity, final TextView textView)
{
final InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
// only will trigger it if no physical keyboard is open
imm.showSoftInput(textView, 0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment