先给EditText设置一个android:imeOptions="actionSearch";
还有记得一定要设置android:singleLine="true";
设置这个没得用android:maxLines="1";
然后:
edittext.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId,KeyEvent event) {
if ((actionId == EditorInfo.IME_ACTION_SEARCH)) {//如果是搜索按钮
//点击搜索要做的操作
}
return false;
}
});