2011-11-14 35 views
4

後顯示我的鍵盤鍵盤顯示的代碼如何強制刪除與SHOW_FORCED

 ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)) 
       .toggleSoftInput(InputMethodManager.SHOW_FORCED, 
         InputMethodManager.HIDE_IMPLICIT_ONLY); 
     etContent.requestFocus(); 

在下一步我誇大新的LinearLayout和調用的setContentView(newLayout)和鍵盤仍然存在。如何強制刪除鍵盤?我試過

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 

但它沒有幫助。有人可以提出我的解決方案嗎?

+0

檢查這個答案 - > http://stackoverflow.com/questions/6647008/android-3-1-soft-keyboard-in-fullscreen-模式/ 7832810#7832810 – guleryuz

回答

6

試試看。我用這個來隱藏軟輸入多次。

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); 
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
imm.hideSoftInputFromWindow(getContentView().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); 
+0

從我+1,謝謝。如果你碰巧看到這樣的評論:你是否知道爲什麼'setSoftInputMode()'有時會這樣做,有時候不會呢? – jerry

+1

我不是100%確定的,如果你不傳遞任何參數,我想這個方法有默認值。 – JoeLallouz

+0

這是非常有用的答案,但'getContentView()'在我的Activity中沒有解決,所以我只是用'getWindow()。getDecorView()'替換它。現在它對我來說是完美的。 :) –

0

試試這個,它應該工作

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
imm.hideSoftInputFromWindow(getContentView().getWindowToken(), 0);