我的Activity有一个EditText,一个按钮和一个ListView。其目的是在EditText中键入搜索屏幕,按下按钮,让搜索结果填充此列表。
这一切都很完美,但虚拟键盘的行为却很奇怪。
如果我点击EditText,我就会看到虚拟键盘。如果我点击虚拟键盘上的“完成”按钮,它就会消失。但是,如果我在点击虚拟键盘上的“完成”之前点击我的搜索按钮,虚拟键盘仍然存在,我无法摆脱它。单击“完成”按钮不会关闭键盘。它会将“完成”按钮从“完成”更改为一个箭头,并保持可见。
谢谢你的帮忙
发布于 2010-09-17 23:47:35
mMyTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
// hide virtual keyboard
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(m_txtSearchText.getWindowToken(),
InputMethodManager.RESULT_UNCHANGED_SHOWN);
return true;
}
return false;
}
});发布于 2011-11-22 03:34:59
InputMethodManager inputManager = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);我把这个放在onClick(View v)事件之后。
需要导入android.view.inputmethod.InputMethodManager;
单击该按钮时,键盘将隐藏。
发布于 2014-12-01 20:43:31
在代码下面使用
your_button_id.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
} catch (Exception e) {
}
}
});https://stackoverflow.com/questions/3400028
复制相似问题