连续按2次返回键退出应用 隐藏软键盘

private static long firstTime;
/**
* 连续按两次返回键就退出
*/
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
if (firstTime + 2000 > System.currentTimeMillis()) {
super.onBackPressed();
} else {
ShowToast("再按一次退出程序");
}
firstTime = System.currentTimeMillis();

}


//隐藏软键盘
public void hideSoftInputView() {
InputMethodManager manager = ((InputMethodManager) this.getSystemService(Activity.INPUT_METHOD_SERVICE));
if (getWindow().getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
if (getCurrentFocus() != null)
manager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}

// 显示软键盘
public void showSoftInputView() {
if (getWindow().getAttributes().softInputMode == WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
if (getCurrentFocus() != null)
((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
.showSoftInput(edit_user_comment, 0);
}
}

你可能感兴趣的:(连续按2次返回键退出应用 隐藏软键盘)