点击屏幕其他地方让软键盘消失
2015-02-27 15:06
288 查看
/*
在获取不到焦点的时候隐藏软键盘
*/
@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);
}
}
}
在获取不到焦点的时候隐藏软键盘
*/
@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);
}
}
}
相关文章推荐
- 关于popupWindow点击屏幕其他地方或返回键消失
- Dialog点击屏幕其他地方消失的事件
- android 实现点击屏幕其他地方popupwindow消失
- 安卓editview点击时打开软键盘,点击其他地方软键盘消失(Activity中)
- 关于安卓alertdialog你能用到的都在这里了(进出动画,显示位置,背景,设置内容,是否可以点击其他地方消失,屏幕不变暗)
- 安卓editview点击时打开软键盘,点击其他地方软键盘消失(fragment中)
- android实现点击屏幕其他地方popupwindow消失
- 打开关闭软键盘,点击屏幕其他地方关闭软键盘
- 点击页面其他地方的时候,让弹出框消失
- 高德地图infowindow点击其他地方消失
- 点击其他地方界面消失
- 点击屏幕其他地方让edittext失去焦点 的实现
- 点击屏幕其他地方让edittext失去焦点 的实现
- js使点击网页其他地方使显示框消失
- MBProgressHUD 显示后,为何不能点击屏幕其他地方
- 点击其他地方弹层消失
- 关于popwindow ListView 动画,点击其他地方消失
- TrackPopupMenu SetCheck(1)无效? 点击其他地方快捷菜单不消失?
- 高德地图infowindow点击其他地方消失
- UITextField 弹出输入面板后,点击其他地方使其消失