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 hideKeyboard(Activity activity, EditText edt) {
    final InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (edt != null) {
        imm.hideSoftInputFromWindow(edt.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    } else {/*from  w w  w .  j  a  v  a2  s. c o  m*/
        if (activity.getCurrentFocus() != null) {
            imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }
}

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.isActive()) {
            imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
        }/*from www.  j ava2  s. co  m*/
    }
}

From source file:Main.java

public static void hideKeyBoard(final Activity activity) {
    if (activity == null)
        return;/*  www. j av a 2 s.  c  o m*/
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            InputMethodManager mgr = (InputMethodManager) activity
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            mgr.hideSoftInputFromWindow(activity.getWindow().getDecorView().getWindowToken(), 0);

        }
    });
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static void hideSoftInput(Activity activity) {
    View view = activity.getWindow().peekDecorView();
    if (view != null) {
        InputMethodManager inputmanger = (InputMethodManager) activity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }/*from  w ww.j a  v a2s.c o  m*/
}

From source file:Main.java

public static void hideSoftKeyPad(Context context, View view) {
    try {/*from  w w  w. ja va 2s. co m*/
        if (view == null) {
            return;
        } else if (view.getWindowToken() == null) {
            return;
        }

        InputMethodManager inputManager = (InputMethodManager) context
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    } catch (Throwable ex) {
    }
}

From source file:Main.java

public static boolean hideInputSoft(View trigger) {
    InputMethodManager inputMethodManager = (InputMethodManager) trigger.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    return inputMethodManager.hideSoftInputFromWindow(trigger.getWindowToken(),
            InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static void hideSoftInput(Context context) {
    View view = ((Activity) context).getWindow().peekDecorView();
    if (view != null) {
        InputMethodManager inputmanger = (InputMethodManager) context
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }//w w  w  .  j a  va2  s .  c om
}

From source file:Main.java

public static void hideKeyboard(View view) {
    InputMethodManager inputMethodManager = (InputMethodManager) view.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

From source file:Main.java

public static void closeSoftKeyboard(Context context) {
    if (context == null || !(context instanceof Activity) || ((Activity) context).getCurrentFocus() == null) {
        return;//from   ww w.  ja v  a  2  s  .c o m
    }
    try {
        InputMethodManager inputMethodManager = (InputMethodManager) context
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(((Activity) context).getCurrentFocus().getWindowToken(),
                InputMethodManager.HIDE_NOT_ALWAYS);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void hideKeyboard(Context context, View editText) {
    try {//from   w w  w .  j a  v  a 2  s .c o  m
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (editText != null) {
            imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
            editText.clearFocus();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}