1
簡單的問題 - 如何在點擊回車鍵/按鈕後關閉虛擬鍵盤?按Enter鍵後隱藏鍵盤
我試過這個Handle 「Enter」 key on Jelly Bean和How to hide keyboard on enter key,但這些都不適合我。
簡單的問題 - 如何在點擊回車鍵/按鈕後關閉虛擬鍵盤?按Enter鍵後隱藏鍵盤
我試過這個Handle 「Enter」 key on Jelly Bean和How to hide keyboard on enter key,但這些都不適合我。
你有兩種選擇。
使用XML:
<EditText
android:id="@+id/editText1"
android:inputType="text"
android:imeOptions="actionDone"/>
與代碼。
edittext.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (event != null&& (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
in.hideSoftInputFromWindow(edittext.getApplicationWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);
}
return false;
}
});
XML代碼有效,但Java代碼無效。仍然想知道爲什麼不。 – MatusMak
第二個鏈接中的代碼應該工作,我將提供相同的答案。當你嘗試時會發生什麼? – Coderji
由於某種原因沒有任何結果,輸入密鑰就像通常那樣工作。 – MatusMak