Created
January 18, 2019 18:35
-
-
Save dilovan/38d83ca6f3ea493e5e568e45ba7ac76d to your computer and use it in GitHub Desktop.
android os hide 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
// hide keyboard | |
public static void hideKeyboard(Activity activity) { | |
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); | |
//Find the currently focused view, so we can grab the correct window token from it. | |
View view = activity.getCurrentFocus(); | |
//If no view currently has focus, create a new one, just so we can grab a window token from it | |
if (view == null) { | |
view = new View(activity); | |
} | |
imm.hideSoftInputFromWindow(view.getWindowToken(), 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment