1、隐藏软键盘
1 private void hideSoftInput(){2 // 隐藏软键盘3 InputMethodManager inputManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);4 if (inputManager != null && getActivity().getCurrentFocus()!=null) {5 inputManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),6 InputMethodManager.HIDE_NOT_ALWAYS);7 }8 }
2、键盘搜索,完成,下一步等按键监听
//在布局中为EditText控件加入该语句,控件弹出键盘后显示,搜索,其它可自试android:imeOptions="actionSearch"
searchText.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId,KeyEvent event) { if(actionId ==EditorInfo.IME_ACTION_SEARCH){ //做一些事 } return false; } });