Android--輸入法鍵盤隱藏

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
//得到InputMethodManager的實例
if (imm.isActive()) {
//如果開啓
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS);
//關閉軟鍵盤,開啓方法相同,這個方法是切換開啓與關閉狀態的
}

------------------------------------------
//隱藏軟鍵盤
int flags = WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
getWindow().addFlags(flags);

--------------------------------------------
在onclick事件下.以下方法可行.(如果是EditText失去焦點/得到焦點,沒有效果)
InputMethodManager im = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(getCurrentFocus().getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章