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 autoHideInput(final View view, final InputMethodManager imm) {

    if (!(view instanceof EditText)) {
        view.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                return false;
            }//ww w  .  j a va  2s.  co  m

        });
    }

    if (view instanceof ViewGroup) {

        for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
            View innerView = ((ViewGroup) view).getChildAt(i);
            autoHideInput(innerView, imm);
        }
    }
}

From source file:Main.java

public static void closeSoftInput(Context context) {
    InputMethodManager inputMethodManager = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (inputMethodManager != null && ((Activity) context).getCurrentFocus() != null) {
        inputMethodManager.hideSoftInputFromWindow(((Activity) context).getCurrentFocus().getWindowToken(),
                InputMethodManager.HIDE_NOT_ALWAYS);
    }// www.  ja  va  2s.  c o m
}

From source file:Main.java

public static void popSoftKeyboard(Context context, View view, boolean wantPop) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (wantPop) {
        view.requestFocus();/*w ww .  j  a  v a 2  s  . c om*/
        imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
    } else {
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}

From source file:Main.java

public static void popSoftKeyboard(Context context, View view, boolean isShow) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (isShow) {
        view.requestFocus();//from  w ww  . j  a v a 2s.  c  om
        imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
    } else {
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}

From source file:Main.java

public static void setKeyboardVisible(Context context, View view, boolean visible) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Service.INPUT_METHOD_SERVICE);
    if (imm == null) {
        return;/*from w ww .  j a va 2s  . c om*/
    }

    if (visible) {
        imm.showSoftInput(view, 0);
    } else {
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}

From source file:Main.java

public static void hiddenKeyboard(Class className, Context context, Activity activity) {
    try {//from  www.  ja  v a  2 s .com
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);

        if (activity.getCurrentFocus() != null) {
            if (activity.getCurrentFocus().getWindowToken() != null) {
                imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
                        InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:Main.java

public static void hideKeyboard(Context context, View view) {
    if (context != null) {
        InputMethodManager inputMethodManager = (InputMethodManager) context.getApplicationContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        if (inputMethodManager != null) {
            if (view != null) {
                inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }/*from   w ww  .j  a v  a2 s  . c  om*/
        }
    }
}

From source file:Main.java

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

    // check if no view has focus:
    View v = activity.getCurrentFocus();
    if (v == null)
        return;//www. j  av a2s  . c om

    inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
}

From source file:cc.metapro.openct.utils.ActivityUtils.java

public static AlertDialog addViewToAlertDialog(@NonNull final AlertDialog.Builder builder,
        @NonNull final View view) {
    ViewGroup parent = (ViewGroup) view.getParent();
    if (parent != null) {
        parent.removeView(view);/*from  w  w w .  j  av a 2 s.  c  o  m*/
    }

    ScrollView scrollView = new ScrollView(builder.getContext());
    scrollView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    scrollView.addView(view);

    builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            InputMethodManager imm = (InputMethodManager) builder.getContext()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    });

    AlertDialog dialog = builder.setView(scrollView).create();
    Window window = dialog.getWindow();
    if (window != null) {
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    }
    return dialog;
}

From source file:Main.java

/**
 * hide soft keyboard/*from w  ww .ja v  a 2 s .c  o  m*/
 * @param activity
 */
public static void hideSoftKeyboard(Activity activity) {
    if (null == activity) {
        return;
    }
    InputMethodManager inputMethodManager = (InputMethodManager) activity
            .getSystemService(Activity.INPUT_METHOD_SERVICE);
    if (null != inputMethodManager) {
        View view = activity.getCurrentFocus();
        if (null != view) {
            inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }

    }
}