首页 > 代码库 > 切换viewpager时关闭键盘

切换viewpager时关闭键盘

  EditText添加焦点监听事件,当该EditText失去焦点时,关闭键盘。

EditText editTextProfileName = (EditText) view                    .findViewById(R.id.nameEditText);            editTextProfileName.setOnFocusChangeListener(new OnFocusChangeListener() {                public void onFocusChange(View v, boolean hasFocus) {                      if (!hasFocus) {                            hideKeyboard();                        }                }                private void hideKeyboard() {                    if (editTextProfileName != null) {                        InputMethodManager imanager = (InputMethodManager) getActivity()                                .getSystemService(Context.INPUT_METHOD_SERVICE);                        imanager.hideSoftInputFromWindow(editTextProfileName.getWindowToken(), 0);                    }                }            });

  学习自:http://stackoverflow.com/questions/17184119/how-to-hide-soft-key-pad-after-changing-one-viewpager-to-another-view-pager

切换viewpager时关闭键盘