2015-02-17 115 views
1

無法找到明確的答案,基本上我有一個EditText字段的活動。軟鍵盤被設置爲在清單中可見,所以當活動開始時鍵盤是可見的,但是如果用戶導航並使用後退按鈕返回鍵盤隱藏(我需要它在繼續時可見)。 我已將下面的方法添加到我的onResume中,但似乎不起作用? 任何想法我在這裏失蹤?顯示軟鍵盤onResume

private void showSoftKeyboard(){ 
    quickListName.requestFocus(); 
    InputMethodManager imm = D(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
    imm.showSoftInput(quickListName,InputMethodManager.SHOW_IMPLICIT); 
} 

回答

2

試試這個:

imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); 
+0

不錯的,像一個魅力工作!謝謝。 – ScottishUser 2015-02-17 23:27:13

0

嘗試呼籲EditTextclearFocus當您收到onStop回調

+0

如果我正確理解你,我試着重寫onStop()並在編輯文本上添加一個clearFocus,但沒有改變,鍵盤仍然隱藏。 – ScottishUser 2015-02-17 22:26:22

+0

該文檔說[SHOW_IMPLICIT](http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html#SHOW_IMPLICIT)可能不會顯示鍵盤,也許您可​​以使用InputMethodManager.SHOW_FORCED – 2015-02-17 22:41:44

+0

嘗試嘗試此操作沒有變化,鍵盤隱藏時,返回到活動 – ScottishUser 2015-02-17 23:23:48

1

以前,我曾用下面的代碼的onResume()方法和內軟如果僅爲此活動調用onPause()方法,並且我回到此活動,則鍵盤會顯示出來。但是在這種情況下,調用了此活動的onStop()方法。當我再次返回到此活動時,onResume()被調用,但沒有顯示軟鍵盤。

InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
inputMethodManager.showSoftInput(this.getCurrentFocus(), InputMethodManager.SHOW_IMPLICIT); 

我用下面的代碼中的onResume()方法,而不是上面提到的一個顯示軟鍵時也被調用的onStop()爲該活動。

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); 
0

嘗試{ InputMethodManager inputMethodManager =(InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED,0); (例外e){ e.printStackTrace(); }