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 hideSoftKeyboard(Activity activity) {
    if (activity != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
    }//from w  ww . j  av  a 2s .  co m
}

From source file:com.davidmiguel.gobees.utils.AndroidUtils.java

/**
 * Closes / hides soft Android keyboard.
 *
 * @param activity current activity.//from   www.jav a2  s  . c o  m
 */
public static void closeKeyboard(Activity activity) {
    View view = activity.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}

From source file:Main.java

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

From source file:Main.java

public static void hidenInput(Activity ctx) {
    // TODO Auto-generated method stub

    InputMethodManager imm = ((InputMethodManager) ctx.getSystemService(Context.INPUT_METHOD_SERVICE));

    imm.hideSoftInputFromWindow(ctx.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

}

From source file:Main.java

/**
 * Hide soft key board.//from   ww w .  ja v  a  2 s. c  o m
 *
 * @param activity the activity
 */
public static void hideSoftKeyBoard(Activity activity) {
    InputMethodManager inputManager = (InputMethodManager) activity
            .getSystemService(Context.INPUT_METHOD_SERVICE);

    View currentFocus = activity.getCurrentFocus();
    if (currentFocus != null) {
        IBinder windowToken = currentFocus.getWindowToken();
        inputManager.hideSoftInputFromWindow(windowToken, InputMethodManager.HIDE_NOT_ALWAYS);
    } else {
        activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    }
}

From source file:Main.java

private static void hideSoftKeyboard(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(Activity.INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}

From source file:Main.java

/**
 * Hides the soft keyboard//  w w  w .jav  a2  s. c o  m
 *
 * @param activity The reference of the activity displaying the keyboard
 */
public static void hide(@NonNull final Activity activity) {
    final InputMethodManager iManager = (InputMethodManager) activity
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    final View view = activity.getCurrentFocus();
    if (view != null && iManager != null) {
        iManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}

From source file:Main.java

public static void hideKeyoard(Activity activity) {
    InputMethodManager inputMethodManager = (InputMethodManager) activity
            .getSystemService(Activity.INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
            InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:Main.java

public static void showKeyoard(Activity activity) {
    InputMethodManager inputMethodManager = (InputMethodManager) activity
            .getSystemService(Activity.INPUT_METHOD_SERVICE);
    inputMethodManager.showSoftInputFromInputMethod(activity.getCurrentFocus().getWindowToken(),
            InputMethodManager.SHOW_FORCED);
}