連續按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);
}
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章