Android——输入法搜索

Android搜索框输入内容点击键盘的搜索按钮进行搜索

1、在布局XML中的EditView 加入android:imeOptions="actionSearch"

2、监听调用

EditView.setOnEditorActionListener(new OnEditorActionListener() { @Overridepublic boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if(actionId ==EditorInfo.IME_ACTION_SEARCH){ // 先隐藏键盘 ((InputMethodManager) searchText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow( getActivity() .getCurrentFocus() .getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); //实现自己的搜索逻辑                                 return true;      }         return false;      }});

相关文章