标签:
/*
在获取不到焦点的时候隐藏软键盘
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (getCurrentFocus() != null
&& getCurrentFocus().getWindowToken() != null) {
SoftInputMethodManager.hide(this);
}
}
return super.onTouchEvent(event);
}
public class SoftInputMethodManager {
/**
* 隐藏软键盘
*
* @param context
*/
public static void hide(Activity context) {
InputMethodManager imm = (InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(context.getWindow().getDecorView()
.getWindowToken(), 0);
}
}
}
标签:
原文地址:http://www.cnblogs.com/iyuge/p/4303364.html