Example usage for android.app Dialog getCurrentFocus

List of usage examples for android.app Dialog getCurrentFocus

Introduction

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

Prototype

public @Nullable View getCurrentFocus() 

Source Link

Document

Call android.view.Window#getCurrentFocus on the Window if this Activity to return the currently focused view.

Usage

From source file:Main.java

public static void hideSoftInput(Dialog dialog) {
    View view = dialog.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) dialog.getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }/*from  w  w w . ja  v  a 2 s  .co m*/
}

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 dialog The current dialog//from ww  w .j a v  a 2  s  .c  om
 */
public static void show(Dialog dialog) {
    if (dialog != null) {
        show(dialog.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 dialog The current dialog//from  w ww.ja  v  a  2s.c o m
 */
public static void hide(Dialog dialog) {
    if (dialog != null) {
        hide(dialog.getCurrentFocus());
    }
}

From source file:org.solovyev.android.calculator.App.java

public static void hideIme(@NonNull DialogFragment fragment) {
    final Dialog dialog = fragment.getDialog();
    if (dialog == null) {
        return;//from  w  ww .  jav  a 2s .c  om
    }
    final View focusedView = dialog.getCurrentFocus();
    if (focusedView == null) {
        return;
    }
    hideIme(focusedView);
}