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 void hideSoftKeyboard(Activity activity) {
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    View currentFocus = activity.getCurrentFocus();
    if (currentFocus != null) {
        imm.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0);
    }/*  w  w  w  . j  a  va 2 s  .co m*/
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static void setKeyboardVisible(View view, boolean visible) {
    InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(INPUT_METHOD_SERVICE);
    if (visible) {
        imm.showSoftInput(view, 0);//from  ww w  .j  av  a2  s  .  co m
    } else {
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}

From source file:Main.java

public static void hideKeyboard(Activity activity, View view) {
    if (activity != null) {
        if (view != null) {
            InputMethodManager imm = (InputMethodManager) activity
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm != null) {
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }//from   w w w . java2s  .  c om
        } else {
            hideKeyboard(activity);
        }
    }
}

From source file:Main.java

/**
 * Hides the soft keyboard.// w  ww . ja v a2  s  .  c om
 *
 * @param view The view object's reference from which we'll get the window token.
 */
public static void hide(@NonNull final View view) {
    final InputMethodManager iManager = (InputMethodManager) view.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (iManager != null) {
        iManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}

From source file:Main.java

public static void hideKeyboard(Activity activity) {
    if (activity != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null && activity.getCurrentFocus() != null) {
            imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
            activity.getCurrentFocus().clearFocus();
        }/*from   w ww.  ja  v  a 2  s  .  co m*/
    }
}

From source file:Main.java

public static void hideSoftInput(Activity activity) {
    View currentFocus = activity.getCurrentFocus();
    if (currentFocus != null) {
        IBinder windowToken = currentFocus.getWindowToken();
        if (windowToken != null) {
            InputMethodManager manager = (InputMethodManager) (activity
                    .getSystemService(Context.INPUT_METHOD_SERVICE));
            if (manager != null) {
                manager.hideSoftInputFromWindow(windowToken, InputMethodManager.HIDE_NOT_ALWAYS);
            }//from  ww w  . jav a 2  s .  c o  m
        }
    }
}

From source file:Main.java

public static void hideKeyboard(android.app.Activity _activity) {
    InputMethodManager inputManager = (InputMethodManager) _activity
            .getSystemService(Context.INPUT_METHOD_SERVICE);

    if (_activity.getCurrentFocus() != null) {
        inputManager.hideSoftInputFromWindow(_activity.getCurrentFocus().getWindowToken(),
                InputMethodManager.HIDE_NOT_ALWAYS);
    } else {/*w w  w.  j  av a  2s  .c  om*/
        inputManager.hideSoftInputFromWindow(null, InputMethodManager.HIDE_NOT_ALWAYS);
    }
}

From source file:Main.java

public static void hideSoftKeyBoard(InputMethodManager imm, View... views) {
    if (views != null && imm != null) {
        for (View view : views) {
            if (view != null) {
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }//from   w  w w . j a  v  a  2 s.c  o m
        }
    }
}

From source file:Main.java

public static void hideSoftInputFromWindow(Context context, View... views) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (views != null && views.length > 0) {
        for (View view : views) {
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }/*from w ww.ja  v a2s .c om*/
    }
}

From source file:Main.java

public static void hideKeyboard(View view) {
    if (view == null) {
        return;//from w  w w  .  ja v  a  2s .c  o  m
    }
    InputMethodManager imm = (InputMethodManager) view.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (!imm.isActive()) {
        return;
    }
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}