1.只需要在EditText中设置imeOptions这个属性就可以了
<EditText
android:id="@+id/editSerch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:imeOptions="actionSearch"
android:singleLine="true"
android:gravity="center" />
2.点击回车按钮的监听事件
edit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {//按下搜索
}
return false;//返回true,保留软键盘。false,隐藏软键盘
}
});