1、布局设置
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:imeOptions="actionSearch"
android:singleLine="true" />
2、监听设置
EditText.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
if (i == KeyEvent.KEYCODE_ENTER && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
// 收起软键盘
((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(
AttentionStoreActivity.this
.getCurrentFocus()
.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
// 其他操作
...
return true;
}
return false;
}
});