hide soft keyboard android code example
Example 1: android hide keyboard
public void hideKeyboard(Context context, View view) {
InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
hideKeyboard(this, view);
hideKeyboard(this, getCurrentFocus());
hideKeyboard(this, getWindow().getDecorView());
hideKeyboard(this, findViewById(android.R.id.content));
Example 2: How to programmatically hide Android soft keyboard
private void closeSoftKeyboard()
{
View v = this.getCurrentFocus();
if (v != null) {
InputMethodManager inputManager
= (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}