我想在活动开始时清除物理键。当用户单击EditText上的Enter时,我有一个活动可以打开另一个活动。下面的功能checkAnswer()将显示一个新活动。使用软键可以正常工作。但是使用物理密钥,不需要的输入将发送到新活动。
我想是因为在onEditorAction()返回true之前调用了新活动-所以Android系统认为我的处理程序不使用enter,而是将条目发送到新活动。
@Override
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
if (event==null) {
if ((actionId != EditorInfo.IME_ACTION_DONE) && (actionId != EditorInfo.IME_ACTION_NEXT)) {
return false;
}
}
else {
if (actionId == EditorInfo.IME_NULL) {
if (event.getAction()==KeyEvent.ACTION_UP) {}
else {
return true;
}
}
else {
return false;
}
}
checkAnswer();
return true;
}
只想在新活动开始时清除键缓冲区。
答案 0 :(得分:0)
public static void hideKeyboard(Activity activity) {
InputMethodManager imm = (InputMethodManager)
activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
//Find the currently focused view, so we can grab the correct window token from it.
View view = activity.getCurrentFocus();
//If no view currently has focus, create a new one, just so we can grab a window
token from it
if (view == null) {
view = new View(activity);
}
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}