Example usage for android.content Context INPUT_METHOD_SERVICE

List of usage examples for android.content Context INPUT_METHOD_SERVICE

Introduction

In this page you can find the example usage for android.content Context INPUT_METHOD_SERVICE.

Prototype

String INPUT_METHOD_SERVICE

To view the source code for android.content Context INPUT_METHOD_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.view.inputmethod.InputMethodManager for accessing input methods.

Usage

From source file:Main.java

public static void hideSoftInput(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  . j  a va2  s.c  o  m*/
}

From source file:Main.java

public static void closeSoftKeyboard(View view) {
    if (view == null || view.getWindowToken() == null) {
        return;//from w ww .java 2s  .c  o  m
    }
    InputMethodManager imm = (InputMethodManager) view.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

From source file:Main.java

public static void showKeyboard(Activity from, EditText editText) {
    InputMethodManager imm = (InputMethodManager) from.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
}

From source file:Main.java

public static void hideSoftKeyBoard(Activity activity) {
    final View v = activity.getWindow().peekDecorView();
    if (v != null && v.getWindowToken() != null) {
        try {//from w  w  w . ja v a 2  s . com
            ((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE))
                    .hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:Main.java

public static void showSoftInputMethod(Context context, EditText editText) {
    if (context != null && editText != null) {
        editText.requestFocus();// ww w  .  ja v  a  2 s.c o m
        InputMethodManager inputManager = (InputMethodManager) context
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.showSoftInput(editText, 0);
    }
}

From source file:Main.java

/**
 * Hides the soft keyboard.//from   w w  w  .  j  av  a2 s  .  com
 *
 * @param view The view object's reference from which we'll get the window token.
 */
public static void hide(@NonNull final View view) {
    final InputMethodManager iManager = (InputMethodManager) view.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (iManager != null) {
        iManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}

From source file:Main.java

public static void showInputMethodPicker(Context context) {
    ((InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE)).showInputMethodPicker();
}

From source file:Main.java

public static final void HideSoftKeyboard(View view, Context context) {
    if (view == null || context == null)
        return;/*from  ww  w .  ja v a  2s  .c o  m*/
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    imm = null;
}

From source file:Main.java

/**
 * Force hide soft keyboard with specific flag.
 * @param context Context to get system service input method.
 * @param viewBinder View has current focus. Can achived by View.getWindowToken().
 * @param flags InputMethodManager flags.
 *///  w ww . j ava  2  s  . c o m
public static void hideKeyboard(Context context, View viewBinder, int flags) {
    InputMethodManager inputManager = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.hideSoftInputFromWindow(viewBinder.getWindowToken(), flags);
}

From source file:Main.java

private static void toggleSoftInput(Context context, View v, boolean hide) {
    if (context != null && v != null) {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (hide)
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        else//from   w w  w  . j av a 2 s.  c  o m
            imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT);
    }
}