Android控制软键盘显示和隐藏的工具类
public class KeyboardUtils {
public static void showKeyboard(EditText editText) {
InputMethodManager inputMethodManager = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {
editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
editText.requestFocus();
inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}
}
public static void hideKeyboard(EditText editText){
InputMethodManager imm = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
editText.clearFocus();
imm.hideSoftInputFromWindow(editText.getWindowToken(),0);
}
}
}