xml中设置EditText的属性,并且设置inputType
android:inputType="text"
android:imeOptions="actionSearch"
设置监听,实现TextView.OnEditorActionListener接口
mSearch.setOnEditorActionListener(this);
实现onEditorAction方法
@Overridepublic boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm.isActive()) {
imm.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
getInfoFromNet();
}
return true;
}
return false;
}