editText獲取焦點後,會自動彈出軟鍵盤,關閉的時候一般需要按返回鍵或者點擊軟鍵盤上的按鈕,即使當前activity已經finish掉,軟鍵盤依然存在
在網上找了兩種可用的方法, 在此記錄:
//此方法只是關閉軟鍵盤 可以在finish之前調用一下
private void hintKbTwo() {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
if(imm.isActive()&&getCurrentFocus()!=null){
if (getCurrentFocus().getWindowToken()!=null) {
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
}
//此方法,如果顯示則隱藏,如果隱藏則顯示
private void hintKbOne() {
InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
// 得到InputMethodManager的實例
if (imm.isActive()) {
// 如果開啓
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,
InputMethodManager.HIDE_NOT_ALWAYS);
}
}