我有一个坐在按钮上方的数字edittext的活动。

我已经注意到,如果单击编辑文本并使用硬键盘键入某些号码,请按硬终点,使其将焦点转移到编辑文本下方的按钮,并出现一个QWERTY键盘。如何阻止这种情况发生?

我试图用以下命令控制ENTER键:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activityEnterAmt);

    final EditText editText = (EditText) findViewById(R.id.editTextEnterAmt);
    editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) {
                Log.i("Tag", "Enter pressed or IME Action Submit pressed");
                saveButtonClick(editText);
            }
            return false;
        }
    });
}
.

但我真的想在按Enter键时停止它从键盘打开。我真的不明白为什么这样做?

感谢

有帮助吗?

解决方案

当Edittext失去焦点时,我已经通过关闭软键盘修复了这个问题:

editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (v == editText) {
                if (hasFocus) {
                    ((InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(editText,
                            InputMethodManager.SHOW_FORCED); // open keyboard

                } else {
                    ((InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
                            editText.getWindowToken(), 0); // close keyboard
                }
            }
        }
    });
.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top