随笔碎片

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;
            }
        });

 

posted @ 2014-09-29 17:39  斗胆潇洒  阅读(106)  评论(0编辑  收藏  举报