嗨我正在构建键盘应用程序,当我想最小化键盘时,它会回到之前的活动。例如如果我在whatsapp上与朋友聊天,并希望在按下按钮时最小化键盘,它将返回聊天列表而不是最小化。所以我需要的是当按下后退按钮时它应该最小化键盘而不是回到之前的活动。 如果可以,请帮忙。
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case 4:
if (event.getRepeatCount() == 0 && this.mInputView != null && this.mInputView.handleBack()) {
return PROCESS_HARD_KEYS;
}
case 66:
return false;
case 67:
if (this.mComposing.length() > 0) {
onKey(-5, null);
return PROCESS_HARD_KEYS;
}
break;
default:
if (keyCode == 62 && (event.getMetaState() & 2) != 0) {
InputConnection ic = getCurrentInputConnection();
if (ic != null) {
ic.clearMetaKeyStates(2);
keyDownUp(29);
keyDownUp(42);
keyDownUp(32);
keyDownUp(46);
keyDownUp(43);
keyDownUp(37);
keyDownUp(32);
return PROCESS_HARD_KEYS;
}
}
if (this.mPredictionOn && translateKeyDown(keyCode, event)) {
return PROCESS_HARD_KEYS;
}
}
return super.onKeyDown(keyCode, event);
}
答案 0 :(得分:1)
只是取代这个希望它会起作用。
public boolean onKeyDown(int keyCode, KeyEvent event, View view) {if ((keyCode == KeyEvent.KEYCODE_BACK)) {
// hide keyboard here
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);}
switch (keyCode) {
case 4:
if (event.getRepeatCount() == 0 && this.mInputView != null && this.mInputView.handleBack()) {
return PROCESS_HARD_KEYS;
}
case 66:
return false;
case 67:
if (this.mComposing.length() > 0) {
onKey(-5, null);
return PROCESS_HARD_KEYS;
}
break;
default:
if (keyCode == 62 && (event.getMetaState() & 2) != 0) {
InputConnection ic = getCurrentInputConnection();
if (ic != null) {
ic.clearMetaKeyStates(2);
keyDownUp(29);
keyDownUp(42);
keyDownUp(32);
keyDownUp(46);
keyDownUp(43);
keyDownUp(37);
keyDownUp(32);
return PROCESS_HARD_KEYS;
}
}
if (this.mPredictionOn && translateKeyDown(keyCode, event)) {
return PROCESS_HARD_KEYS;
}
}
return super.onKeyDown(keyCode, event);
}