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

/**
 * Request to hide the soft input window from the context of the window that
 * is currently accepting input./*from w  w  w.j  ava 2s .c  o m*/
 * 
 * @param activity
 *            The currently activity, which shows the view receives soft
 *            keyboard input.
 */
public static void hideKeyboard(Activity activity) {
    if (null == activity) {
        return;
    }
    InputMethodManager im = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    View v = activity.getCurrentFocus();
    if (v != null) {
        im.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }
}

From source file:com.hybris.mobile.app.commerce.utils.UIUtils.java

/**
 * Show/Hide the keyboard/*from  w  w w.  j a va 2 s.  c o  m*/
 *
 * @param activity
 */
public static void hideKeyboard(Activity activity) {
    if (activity != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(activity.findViewById(android.R.id.content).getWindowToken(), 0);
    }
}

From source file:Main.java

/**
 * Hide input method./*from w ww. java  2s .  com*/
 *
 * @param activity
 */
public static void hideInputMethod(Activity activity) {
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    View currentFocus = activity.getCurrentFocus();
    if (currentFocus != null) {
        imm.hideSoftInputFromWindow(currentFocus.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }
}

From source file:Main.java

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.ja  va  2s  .c  o  m
    } else {
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}

From source file:Main.java

public static void hideSoftKeyboard(Activity a) {
    InputMethodManager inputMethodManager = (InputMethodManager) a
            .getSystemService(Activity.INPUT_METHOD_SERVICE);
    if (a.getCurrentFocus() != null && a.getCurrentFocus().getWindowToken() != null)
        inputMethodManager.hideSoftInputFromWindow(a.getCurrentFocus().getWindowToken(), 0);
}

From source file:Main.java

public static void showInputMethod(Activity activity) {
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    View currentFocus = activity.getCurrentFocus();
    if (currentFocus != null) {
        imm.hideSoftInputFromWindow(currentFocus.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        imm.showSoftInput(currentFocus, InputMethodManager.SHOW_IMPLICIT);
    }//from   w  w  w  .j  a v  a2 s.c om

    //        if (imm != null) {
    //            imm.viewClicked(this);
    //        }
    //        if (imm != null && getShowSoftInputOnFocus()) {
    //            imm.showSoftInput(this, 0);
    //        }
}

From source file:Main.java

public static void closeInput(Activity activity) {
    InputMethodManager inputMethodManager = (InputMethodManager) activity
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (inputMethodManager != null && activity.getCurrentFocus() != null) {
        inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
                InputMethodManager.HIDE_NOT_ALWAYS);
    }/* w w w  .j  a  v  a2 s  .c om*/
}

From source file:Main.java

/**
 * This method hides the keyboard/*from w w w .  j av a 2  s.  c om*/
 *
 * @param activity
 *         Active activity
 */
public static void hideKeyboard(Activity activity) {
    InputMethodManager inputManager = (InputMethodManager) activity
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    View view = activity.getCurrentFocus();
    if (view != null) {
        inputManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
                InputMethodManager.HIDE_NOT_ALWAYS);
    }
}

From source file:Main.java

/**
 * Dismiss the keyboard for the given activity.
 * @param activity to dismiss associated keyboard for.
 *///from   ww w.ja  va2s  .c  o  m
public static void hideKeyboard(@NonNull Activity activity) {
    InputMethodManager inputManager = (InputMethodManager) activity
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    View focus = activity.getCurrentFocus();
    if (focus != null) {
        inputManager.hideSoftInputFromWindow(focus.getWindowToken(), 0);
    }
}

From source file:Main.java

public static void hideKeyboard(View view) {
    if (view == null) {
        return;/*from w  ww.ja va2 s .c  o m*/
    }
    try {
        InputMethodManager imm = (InputMethodManager) view.getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        if (!imm.isActive()) {
            return;
        }
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    } catch (Exception e) {
        e.printStackTrace();
    }
}