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
时间: 2024-10-17 07:07:57