Example usage for android.view View getWindowToken

List of usage examples for android.view View getWindowToken

Introduction

In this page you can find the example usage for android.view View getWindowToken.

Prototype

public IBinder getWindowToken() 

Source Link

Document

Retrieve a unique token identifying the window this view is attached to.

Usage

From source file:Main.java

public static void closeInputMethod(final Activity activity, final View view) {
    final InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

From source file:Main.java

/**
 * Close the soft key board//from w w  w .  j  a  v  a  2 s  .  c  o m
 */
public static void closeSoftKeyBoard(Activity pActivity) {
    if (pActivity != null) {
        final InputMethodManager inputMethodManager = (InputMethodManager) pActivity
                .getSystemService(Activity.INPUT_METHOD_SERVICE);
        if (inputMethodManager != null) {
            final View currentFocus = pActivity.getCurrentFocus();
            if (currentFocus != null) {
                inputMethodManager.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0);
            }

        }
    }
}

From source file:Main.java

public static void hideKeyboard(FragmentActivity activity, View view) {
    // Hide Keyboard
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

From source file:Main.java

public static void hideSoftKeyBoard(Context context, final View... views) {
    try {/*from   ww w.  jav a  2 s .  co m*/
        final InputMethodManager imm = (InputMethodManager) context
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                try {
                    if (views != null) {
                        for (View view : views) {
                            if (view != null) {
                                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                            }
                        }
                    }
                } catch (Exception e) {
                }
            }
        }, 200);
    } catch (Exception e) {
    }
}

From source file:Main.java

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

From source file:Main.java

public static void closeKeyBoard(Context context, View view) {
    view.clearFocus();//from  w  w w  .j a va 2s .  c o m
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

From source file:Main.java

public static void hideKeyboard(Context context, View edt) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm != null)
        imm.hideSoftInputFromWindow(edt.getWindowToken(), 0);
}

From source file:Main.java

public static void hideInputSoftFromWindowMethod(Context context, View view) {
    try {//  w w w .ja  v  a  2  s.  c  o m
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void hideInputMethod(Context context, View v) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm != null) {
        imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
    }/*from ww w .  ja  v  a2 s  .c om*/
}

From source file:Main.java

public static void shutInput(Context context, View view) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm.isActive()) {
        imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }// w  ww.  j a va2  s  .co  m
}