/*
在获取不到焦点的时候隐藏软键盘
*/
@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);
}
}
}
时间: 2024-11-10 07:58:17