Example usage for android.view.inputmethod InputMethodManager hideSoftInputFromWindow

List of usage examples for android.view.inputmethod InputMethodManager hideSoftInputFromWindow

Introduction

In this page you can find the example usage for android.view.inputmethod InputMethodManager hideSoftInputFromWindow.

Prototype

public boolean hideSoftInputFromWindow(IBinder windowToken, int flags) 

Source Link

Document

Synonym for #hideSoftInputFromWindow(IBinder,int,ResultReceiver) without a result: request to hide the soft input window from the context of the window that is currently accepting input.

Usage

From source file:Main.java

public static boolean hideSoftInput(View view) {
    InputMethodManager imm = (InputMethodManager) view.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    return imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

From source file:Main.java

public static void closeKeyboard(Activity activity) {
    View view = activity.getWindow().peekDecorView();
    if (view != null) {
        InputMethodManager inputMethodManager = (InputMethodManager) activity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }//from   w w  w. j  a v  a  2  s .  co  m
}

From source file:Main.java

public static void closeSoftInputMethod(Context context, EditText editText) {
    if (context != null && editText != null) {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
        }/*from ww w  .ja  va2  s .c  om*/
    }
}

From source file:Main.java

/**
 * Helper to hide the keyboard/*from  w w w  .  ja  v a  2  s.c o  m*/
 *
 * @param act
 */
public static void hideKeyboard(Activity act) {
    if (act != null && act.getCurrentFocus() != null) {
        InputMethodManager inputMethodManager = (InputMethodManager) act
                .getSystemService(Activity.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(act.getCurrentFocus().getWindowToken(), 0);
    }
}

From source file:Main.java

public static void hideSoftKeyboard(Activity activity) {
    if (activity.getCurrentFocus() != null) {
        InputMethodManager inputMethodManager = (InputMethodManager) activity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
    }//from   w w w.  j a  v a  2s .c o  m
}

From source file:Main.java

public static void hiddenKeyBoard(View view) {
    InputMethodManager imm = (InputMethodManager) view.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm.isActive())
        imm.hideSoftInputFromWindow(view.getApplicationWindowToken(), 0);
}

From source file:Main.java

public static void hideSoftKeyboard(View view) {
    if (view == null)
        return;/*from  ww w .  j  a v a  2  s . co  m*/
    View mFocusView = view;

    Context context = view.getContext();
    if (context != null && context instanceof Activity) {
        Activity activity = ((Activity) context);
        mFocusView = activity.getCurrentFocus();
    }
    if (mFocusView == null)
        return;
    mFocusView.clearFocus();
    InputMethodManager manager = (InputMethodManager) mFocusView.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    manager.hideSoftInputFromWindow(mFocusView.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:Main.java

private static void toggleSoftInput(Context context, View v, boolean hide) {
    if (context != null && v != null) {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (hide)
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        else//from  w  ww.  j  a va2 s .  c  o m
            imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT);
    }
}

From source file:Main.java

/**
 * Hide soft input from window.//from   w  w  w  .  j  av  a2s .  c  om
 * @param activity
 */
public static void forceHideSoftInput(Activity activity) {
    try {
        InputMethodManager inputMethodManager = (InputMethodManager) activity
                .getSystemService(Activity.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
    } catch (Exception e) {

    }
}

From source file:Main.java

/**
 * Request to hide the soft input window from the context of the window that
 * is currently accepting input./*from  w w w .  j a va2 s . c  om*/
 * 
 * @param view
 *            he currently focused view, which would like to receive soft
 *            keyboard input.
 */
public static void hideKeyboard(View view) {
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) view.getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}