安卓隐藏键盘与点击空白区域隐藏键盘

隐藏键盘
1.在Manifests文件中实现
android:windowSoftInputMode=”stateHidden|adjustResize”
2.在Activity点击事件中实现
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE).hideSoftInputFromWindow(v.getWindowToken(), 0);

点击空白区域隐藏键盘
private InputMethodManager manager=null;
manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (getCurrentFocus() != null
&& getCurrentFocus().getWindowToken() != null) {
manager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
return super.onTouchEvent(event);
}

感谢“Hensen_”与“gqdy365”提供的帮助

猜你喜欢

转载自blog.csdn.net/Android_Programmer/article/details/76423154