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 hideSoftKeyBoard(Activity activity) {
    if (null == activity.getCurrentFocus()) {
        return;/*w ww.j a v a 2s  .  co  m*/
    }
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
            InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:Main.java

/**
 * Toggle Soft Input.//from  w  w w .  ja  va 2  s. co  m
 * @param context
 */
public static void toggleSoftInput(Context context) {
    InputMethodManager inputManager = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_IMPLICIT_ONLY);
}

From source file:Main.java

public static void showInputMethodWindow(Activity activity, View view) {
    try {/*from   w  w w  .  j  a  v a2 s  . c  om*/
        ((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(view,
                InputMethodManager.SHOW_IMPLICIT);
    } catch (Throwable th) {
        th.printStackTrace();
    }
}

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()) {
            imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
        }/*from  w ww. j  ava 2  s .  c o m*/
    }
}

From source file:Main.java

public static void hideSoftKeyboard(Context context, EditText editText) {
    // editText.setText("");
    editText.clearFocus();//from w  w  w  .j ava 2  s. c  o  m
    InputMethodManager manager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    manager.hideSoftInputFromWindow(editText.getWindowToken(), 0);
}

From source file:Main.java

public static void hideSoftKeyboard(Context context, View view) {
    if (context == null || view == null) {
        return;/*from  w  w w .  j a v  a 2  s.c o  m*/
    }

    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:Main.java

public static void showInputMethod(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);
        imm.showSoftInput(currentFocus, InputMethodManager.SHOW_IMPLICIT);
    }//from  w  w w . j av  a2  s .c o m

    //        if (imm != null) {
    //            imm.viewClicked(this);
    //        }
    //        if (imm != null && getShowSoftInputOnFocus()) {
    //            imm.showSoftInput(this, 0);
    //        }
}

From source file:Main.java

public static void showSoftKeyboard(Context context, View view) {
    if (view.requestFocus()) {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
    }/*from  w w  w.j a  v  a2  s .  c  o m*/
}

From source file:Main.java

public static void hideKeyboard(Context context, View view) {
    view.requestFocus();/*w w w. j a v a2s.  com*/
    imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:Main.java

public static void hide(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. ja  va2 s . co m*/
}