Android SearchView:单击“完成”按钮时,不会发生任何事情
下面是一段:Android SearchView:单击“完成”按钮时,不会发生任何事情,android,Android,下面是一段: searchViewEditText.setImeOptions(EditorInfo.IME_ACTION_DONE); searchViewEditText.setSingleLine(true); 因此,当键盘打开时,将显示按钮Done。 嗯 结果如下: 但当我点击按钮“完成”时,什么也没发生。我希望键盘将被隐藏。您可以使用此选项(设置在EditText上执行操作时调用的特殊侦听器),它对“完成”和“返回”都有效: max.setOnEditorActi
searchViewEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
searchViewEditText.setSingleLine(true);
因此,当键盘打开时,将显示按钮Done。
嗯
结果如下:
但当我点击按钮“完成”时,什么也没发生。我希望键盘将被隐藏。您可以使用此选项(设置在EditText上执行操作时调用的特殊侦听器),它对“完成”和“返回”都有效:
max.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) {
Log.i(TAG,"Enter pressed");
}
return false;
}
});
我想你必须按程序关闭键盘。为此,请向TextView侦听器添加以下逻辑:
editText = (EditText) findViewById(R.id.edit_text);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
InputMethodManager inputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
//Replace <<active view>> With the active view
inputMethodManager.hideSoftInputFromWindow(<<active view>>.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
return false;
}
});
editText=(editText)findViewById(R.id.edit\u text);
editText.setOnEditorActionListener(新的TextView.OnEditorActionListener(){
@凌驾
公共布尔onEditorAction(TextView v、int actionId、KeyEvent事件){
if(actionId==EditorInfo.IME\u ACTION\u DONE){
InputMethodManager InputMethodManager=(InputMethodManager)getContext().getSystemService(Context.INPUT\u方法\u服务);
//替换为活动视图
inputMethodManager.HideOffInputFromWindow(.getCurrentFocus().getWindowToken(),inputMethodManager.HIDE\u不总是);
}
返回false;
}
});
我希望这对您有所帮助:)完成此操作,在这里您可以在按下“完成”按钮后获得回调。