在EditText中添加参数
android:imeOptions="actionSearch"
代码重写监听方法
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId ==EditorInfo.IME_ACTION_SEARCH || actionId ==EditorInfo.IME_ACTION_NEXT){
// 先隐藏键盘
((InputMethodManager) etSearch.getContext().getSystemService(Context.INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
//操作;;;;;;;;
return true;
}
return false;
}