2011-10-10 48 views
2

我有一個問題,只有當我使用AnySoftKeyboard時纔會發生。 我試圖根據EditText焦點顯示/隱藏鍵盤。 我用我this postAnySoftKeyboad在隱藏後仍然保留垃圾數據

發現當我隱藏鍵盤的方法,有一個奇怪的行爲 -

  • 當我旋轉屏幕,那是在的EditText文本加倍。
  • 我認爲它與onCreate方法有關,但是當我單擊「back」(Finish())時,也可以看到它發生。我在活動結束前一分鐘看到它。
  • 當我開始一個新的活動時(ActivityA中的ActivityB),然後單擊「Back」一次不會執行任何操作(可能會「關閉」不可見的鍵盤)。
  • 當我點擊「後退」再次,ActivityB關閉但我可以看到一個瞬間從ActivityA鍵盤大字體的文字在屏幕上(如100毫秒彈出)

有誰有一個想法如何處理它?

+0

顯示您的代碼引用您的確切問題... –

+0

試試這個,http://stackoverflow.com/questions/7289335/soft-keyboard-shows-up-on-edittext-focus-only-once/7291121#7291121 –

回答

1

顯然,這是在AnySoftKeyboard的錯誤。 我沒有發生,當我使用其他鍵盤。

我在隱藏它之前通過對EditText視圖執行setText來解決它 - 它可能會重置鍵盤對象上的某些內容。

這裏是我的代碼:

 View view = getWindow().getCurrentFocus(); 
     if (view==null) 
      return; 

     IBinder binder = view.getWindowToken(); 
     if (binder == null) 
      return; 

     // I used this to fix the strange behaviour 
     if (view instanceof EditText) 
      ((EditText)view).setText(((EditText)view).getText().toString()); 


     InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
     imm.hideSoftInputFromWindow(binder, InputMethodManager.HIDE_NOT_ALWAYS); 

令人驚訝它的工作原理!

0

試試這個:

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0); 
相關問題