fun hideKeybord() {
val view = this.currentFocus
if (view != null) {
val hideKey = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
hideKey.hideSoftInputFromWindow(view.windowToken, 0)
} else {
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
}
}
// Call your function whatever you want
hideKeybord()
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);
}