tôi sử dụng phương pháp này để loại bỏ bàn phím từ chỉnh sửa văn bản:
public static void hideKeyboard(Activity activity, IBinder binder) {
if (activity != null) {
InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
if (binder != null && inputManager != null) {
inputManager.hideSoftInputFromWindow(binder, 0);//HIDE_NOT_ALWAYS
inputManager.showSoftInputFromInputMethod(binder, 0);
}
}
}
Và phương pháp này để loại bỏ bàn phím khỏi hoạt động (không hoạt động trong một số trường hợp - ví dụ, khi edittext, được gắn với bàn phím, mất tiêu điểm, nó sẽ không hoạt động. tại, và bạn không cần phải quan tâm đến yếu tố đó giữ bàn phím)
public static void hideKeyboard(Activity activity) {
if (activity != null) {
InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
if (activity.getCurrentFocus() != null && inputManager != null) {
inputManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
inputManager.showSoftInputFromInputMethod(activity.getCurrentFocus().getWindowToken(), 0);
}
}
}
Nguồn
2015-07-10 10:16:33
Đừng bạn có nghĩa là một EditText (không phải là một TextView)? –