1、弹出软键盘(输入法)。
/**
* 显示软键盘(输入法)
*
* @param activity
* @param editText
*/
public static void showInputMethod(final Activity activity, final EditText editText) {
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
}
2、隐藏软键盘(输入法)。
/**
* 隐藏软键盘(输入法)
*
* @param activity
*/
public static void hideInputMethod(final Activity activity) {
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager.isActive() && activity.getCurrentFocus() != null) {
if (activity.getCurrentFocus().getWindowToken() != null) {
inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}
}
}