我有一个EditText
和按钮对齐到家长的底部。
当我在其中输入文本并按下按钮保存数据时,虚拟键盘不会消失。
有谁能教我怎么隐藏键盘吗?
发布于 2010-02-26 23:56:53
这应该是可行的。
InputMethodManager inputManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);
只需确保this.getCurrentFocus()不返回null,如果没有任何对象具有焦点,它就会返回null。
发布于 2012-04-17 09:58:35
您可能还想在EditText中定义imeOptions。这样,一旦按下Done,键盘就会消失:
<EditText
android:id="@+id/editText1"
android:inputType="text"
android:imeOptions="actionDone"/>
发布于 2015-10-26 15:03:34
mEtNumber.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
// do something, e.g. set your TextView here via .setText()
InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
return true;
}
return false;
}
});
和xml格式
android:imeOptions="actionDone"
https://stackoverflow.com/questions/2342620
复制相似问题