android 隐藏系统键盘
-----------------------------------------已驗證-----------------------------------
?public static void closeBoard(Context mcontext){
??InputMethodManager imm =(InputMethodManager) mcontext
????.getSystemService(Context.INPUT_METHOD_SERVICE);
??//imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
??if(imm.isActive())? //一直是true
???imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,
?????InputMethodManager.HIDE_NOT_ALWAYS);
?}
?
?public static void hideSystemKeyBoard(Contextmcontext,View v) {
??InputMethodManager imm =(InputMethodManager) ((AbstractMmtClientActivity) mcontext)
????.getSystemService(Context.INPUT_METHOD_SERVICE);
??imm.hideSoftInputFromWindow(v.getWindowToken(),0);
?}
?
?
--------------------------------------參考------------------------------------------------
1、對隱藏軟鍵盤有用的函數為:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 它可以用來抑制鍵盤出現,除非用戶接觸了edittext區域。 2、你可以強制android隱藏虛擬鍵盤,用InputMethodManager方法,調用hideSoftInputFromWindow。 InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0); 這樣可以強制在任何條件下隱藏虛擬鍵盤。 ? 3、 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);
轉載于:https://www.cnblogs.com/sharecenter/p/5621009.html
總結
以上是生活随笔為你收集整理的android 隐藏系统键盘的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Win7下Maven的安装与配置
- 下一篇: IM系统中如何保证消息的可靠投递(即Qo