答案 0 :(得分:2)
你试过这个吗?
您可以覆盖活动
上的后退按钮@Override
public void onBackPressed() {
super.onBackPressed();
}
<强>更新强>
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks whether a hardware keyboard is available
if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
Toast.makeText(this, "keyboard visible", Toast.LENGTH_SHORT).show();
} else if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
Toast.makeText(this, "keyboard hidden", Toast.LENGTH_SHORT).show();
}
}
答案 1 :(得分:2)
您可以通过创建自定义EditText并覆盖dispatchKeyEventPreIme()来实现此目的。
public class CustomEditText extends EditText {
public CustomEditText(Context context) {
super(context);
}
public CustomEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomEditText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public boolean dispatchKeyEventPreIme(KeyEvent event) {
// your logic here
return super.dispatchKeyEventPreIme(event); // or return true if you don't want the keyboard to be hidden by system
}
}