Android How to - Hide Input Method








Question

We would like to know how to hide Input Method.

Answer

//from w w w . j  a  v  a2 s. c  o  m
import android.app.Activity;
import android.content.Context;
import android.view.inputmethod.InputMethodManager;

class ActivityUtils {

  public static final void hideInput(Activity activity) {
    InputMethodManager imm = (InputMethodManager) activity
        .getSystemService(Context.INPUT_METHOD_SERVICE);

    if (imm.isActive()) {
      imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,
          InputMethodManager.HIDE_NOT_ALWAYS);
    }
  }
}