Example usage for android.view Window getCurrentFocus

List of usage examples for android.view Window getCurrentFocus

Introduction

In this page you can find the example usage for android.view Window getCurrentFocus.

Prototype

@Nullable
public abstract View getCurrentFocus();

Source Link

Document

Return the view in this Window that currently has focus, or null if there are none.

Usage

From source file:Main.java

public static void hideSoftKeyBoard(final Window window) {
    new Handler().postDelayed(new Runnable() {
        @Override/*from  w  w w.j a v a 2  s  .  c  o  m*/
        public void run() {
            if (window.getCurrentFocus() != null) {
                InputMethodManager inputManager = (InputMethodManager) window.getContext()
                        .getSystemService(Activity.INPUT_METHOD_SERVICE);
                inputManager.hideSoftInputFromWindow(window.getCurrentFocus().getWindowToken(), 0);
            }
        }
    }, 200);
}

From source file:com.ruesga.rview.misc.AndroidHelper.java

public static void hideSoftKeyboard(Context context, Window window) {
    if (window == null) {
        return;//from   w w w.j  av a 2s. com
    }

    View view = window.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}

From source file:com.polatic.pantaudki.utils.UIUtils.java

/**
 * Hide keyboard//from   www.ja v a  2 s  . co  m
 * @param mContext
 * @param activity
 */
public static void hideKeyboard(Context mContext, Window window) {
    InputMethodManager inputManager = (InputMethodManager) mContext
            .getSystemService(Context.INPUT_METHOD_SERVICE);

    inputManager.hideSoftInputFromWindow(window.getCurrentFocus().getWindowToken(),
            InputMethodManager.HIDE_NOT_ALWAYS);
}