Android——输入法搜索

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

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

2、监听调用

EditView.setOnEditorActionListener(new OnEditorActionListener() {
 
@Override
public 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;
      }
});
posted @ 2019-01-13 13:39  听风就是雨~  阅读(764)  评论(0编辑  收藏  举报