不多说,直接上代码
点击隐藏(感谢网上网友)
public boolean onTouchEvent(MotionEvent event) {
if(null != getCurrentFocus()){
InputMethodManager mInputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
return mInputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}
return super .onTouchEvent(event);
}
退出时隐藏(经过多方验证,只找到这个方法)
@Override
public void dismiss() {
View view = getCurrentFocus();
if(view instanceof TextView){
InputMethodManager mInputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
mInputMethodManager.toggleSoftInputFromWindow(view.getWindowToken(), 0, 0);
}
super.dismiss();
}