赞
踩
在xml布局中设置
android:imeOptions="actionSearch"
还需要添加:只显示单行
android:singleLine="true"
然后调用 OnEditorActionListener,不是OnKeyListener
- searchText.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);
-
- //跳转activity
- Intent intent = new Intent();
- intent.setClass(getActivity(), SearchResultActivity.class);
- startActivity(intent);
-
-
-
- return true;
- }
- return false;
- }
- });
转载自:http://www.2cto.com/kf/201408/327967.html
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。