我的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
;
单击该按钮时,键盘将隐藏。
发布于 2010-08-04 04:45:03
您应该为EditView实现OnEditorActionListener
public void performClickOnDone(EditView editView, final View button){
textView.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(EditView v, int actionId, KeyEvent event) {
hideKeyboard();
button.requestFocus();
button.performClick();
return true;
}
});
你可以通过以下方式隐藏键盘:
public void hideKeybord(View view) {
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(),
InputMethodManager.RESULT_UNCHANGED_SHOWN);
}
您还应该使用onClickListener
触发隐藏在按钮中的键盘
现在点击虚拟键盘和按钮上的‘完成’也会做同样的事情-隐藏键盘并执行点击操作。
https://stackoverflow.com/questions/3400028
复制相似问题