Example usage for android.app Activity getCurrentFocus

List of usage examples for android.app Activity getCurrentFocus

Introduction

In this page you can find the example usage for android.app Activity getCurrentFocus.

Prototype

@Nullable
public View getCurrentFocus() 

Source Link

Document

Calls android.view.Window#getCurrentFocus on the Window of this Activity to return the currently focused view.

Usage

From source file:Main.java

public static void hideKeyBoard(Activity activity) {
    if (activity.getCurrentFocus() != null) {
        ((InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
                activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }/*from  w w w.  ja v  a2 s.  c om*/
}

From source file:Main.java

public static void hideSoftKeyboard(Activity activity) {
    if (activity.getCurrentFocus() != null) {
        InputMethodManager inputMethodManager = (InputMethodManager) activity
                .getSystemService(Activity.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
    }/*from w  w w  .j a v  a2  s  . c  o  m*/
}

From source file:Main.java

public static void hideSoftKeyboard(Activity activity) {
    if (null != activity.getCurrentFocus()) {
        ((InputMethodManager) (activity.getSystemService(Activity.INPUT_METHOD_SERVICE)))
                .hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
    }/*from  ww  w  .  j  av a  2 s.c om*/
}

From source file:Main.java

public static void hide(Activity activity) {
    View view = activity.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }//from  w  ww .ja va2 s  .  c o  m
}

From source file:Main.java

public static void hideSoftKeyBoard(Activity activity) {
    if (null == activity.getCurrentFocus()) {
        return;//from w ww . ja v  a  2 s  .c  om
    }
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
            InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:Main.java

public static void hideSoftInput(Activity activity) {
    View view = activity.getCurrentFocus();
    if (view == null)
        view = new View(activity);
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

From source file:Main.java

public static void clearFocuse(Activity activity) {
    try {//from   ww w.  j av a2s  .co m
        activity.getCurrentFocus().clearFocus();
    } catch (Exception e) {
    }
}

From source file:Main.java

public static void hideSoftKeyboard(Activity activity) {
    View view = activity.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }// w w w  . jav  a  2s  .co  m
}

From source file:Main.java

public static void hide(final Activity activity) {
    View view = activity.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }/*from  w w w .j a  v  a2s. c  o  m*/
}

From source file:Main.java

/**
 * Hides the keyboard//from   w ww.  j av  a 2 s  .c  o m
 * @param activity The activity currently active
 */
public static void hideKeyboardFromActivity(Activity activity) {
    View v = activity.getCurrentFocus();
    if (v != null) {
        InputMethodManager inputManager = (InputMethodManager) activity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }
}