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 != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null && activity.getCurrentFocus() != null) {
            imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
            activity.getCurrentFocus().clearFocus();
        }//  ww  w . ja v a 2s  .  c  om
    }
}

From source file:Main.java

/**
 * Hide keyboard/*from   w w w. j ava2 s . c  o m*/
 * 
 * @param activity
 */
public static void hideKeyboard(Activity activity) {

    InputMethodManager inputMethodManager = (InputMethodManager) activity
            .getSystemService(Activity.INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}

From source file:Main.java

public static void hideSoftKeyboard(Activity activity) {

    InputMethodManager inputMethodManager = (InputMethodManager) activity
            .getSystemService(Context.INPUT_METHOD_SERVICE);

    inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
            InputMethodManager.HIDE_IMPLICIT_ONLY);
}

From source file:Main.java

public static void hideSoftKeyboard(final Activity activity) {
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm == null) {
        return;/*  w  ww. java2  s .co  m*/
    }
    View view = activity.getCurrentFocus();
    if (view == null) {
        view = new View(activity);
    }
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

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;//w w w.  ja v  a2 s .c  o m

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

From source file:Main.java

public static void hideKeyboard(Context context) {
    Activity activity = (Activity) context;
    if (activity != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm.isActive() && activity.getCurrentFocus() != null) {
            imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
        }/* ww w .j a va2s. c om*/
    }
}

From source file:com.shopgun.android.utils.KeyboardUtils.java

/**
 * Request to show the soft input window from the context of the window that is currently accepting input.
 * @param activity The current activity// w  ww .  j av  a 2  s. c o m
 */
public static void show(Activity activity) {
    if (activity != null) {
        show(activity.getCurrentFocus());
    }
}

From source file:com.shopgun.android.utils.KeyboardUtils.java

/**
 * Request to hide the soft input window from the context of the window that is currently accepting input.
 * @param activity The current activity//from   w  w w.  ja v  a2 s .  c  o m
 */
public static void hide(Activity activity) {
    if (activity != null) {
        hide(activity.getCurrentFocus());
    }
}

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()) {
            View v = activity.getCurrentFocus();
            if (v != null)
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }/*from   w  w w .  j ava 2 s.co m*/
    }
}

From source file:Main.java

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