Last active
August 29, 2015 14:08
-
-
Save yyunikov/9adceac7e5c1de2f940e to your computer and use it in GitHub Desktop.
Android: some utilities for working with keyboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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