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:com.lixplor.fastutil.utils.control.KeyboardUtil.java

public static View getFocusedView(Activity activity) {
    return activity.getCurrentFocus();
}

From source file:Main.java

/**
 * Hide input method./*from w  w  w  .j a  v  a2s.  c  o  m*/
 *
 * @param activity
 */
public static void hideInputMethod(Activity activity) {
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    View currentFocus = activity.getCurrentFocus();
    if (currentFocus != null) {
        imm.hideSoftInputFromWindow(currentFocus.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }
}

From source file:Main.java

public static void hideSoftKeyboard(Activity activity) {
    InputMethodManager manager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
    manager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}

From source file:Main.java

public static void hideSoftKeyboard(Activity activity) {
    try {/*from  ww  w.  ja v a  2  s . c o m*/
        ((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
                activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    } catch (Exception e) {
    }
}

From source file:Main.java

public static void hideSoftKeyboard(Activity activity) {
    try {/*from w ww. ja  v  a2 s . c om*/
        ((InputMethodManager) activity.getSystemService(activity.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
                activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    } catch (Exception e) {
    }
}

From source file:Main.java

public static void hideSoftKeyboard(Activity activity) {
    try {//from  www  .  jav  a2  s . c om
        ((InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE))
                .hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
    } catch (Exception e) {
        // do nothing
    }
}

From source file:Main.java

public static void closeInputMethodWindow(Activity activity) {
    try {/*ww w  .ja  va 2  s. co m*/
        ((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
                activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    } catch (Throwable th) {
        th.printStackTrace();
    }
}

From source file:Main.java

public static void hideKkeyboard(Activity activity) {
    try {/*w  w  w.j  a v  a 2 s  .  co  m*/
        ((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
                activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void hideKeyboard(Activity activity) {
    try {/*w ww . ja  v  a  2 s.  c o m*/
        ((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
                activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:me.panpf.tool4a.util.InputMethodUtils.java

/**
 * ??//  w  ww. j a  v  a2  s  .  c  om
 */
public static void hideSoftInput(Activity activity) {
    View currentFocusView = activity != null ? activity.getCurrentFocus() : null;
    if (currentFocusView == null) {
        return;
    }

    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(currentFocusView.getWindowToken(), 0);
}