How to hide keyboard in android

w‮.ww‬lautturi.com
How to hide keyboard in android
public void hideKeyboard(Context context, View view) {
	//If no view currently has focus
	if (view == null) {
        return;
    }
    Context context = view.getContext();
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

usage:

// call from inside an Activity...
hideKeyboard(this, view);
hideKeyboard(this, getWindow().getDecorView());
hideKeyboard(this, findViewById(android.R.id.content));
hideKeyboard(this, getCurrentFocus());
Created Time:2017-08-30 21:01:31  Author:lautturi