setOnKeyListener函数可在某些手机上使用,但在其他手机上则无法使用

时间:2019-02-02 19:48:44

标签: java android

所以我有一个功能,该功能应该侦听要按下的Enter键,然后隐藏键盘,但是当我测试时,它可以在一种设备上运行,而在另一台设备上不能运行。

我的功能:

notes.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() != KeyEvent.ACTION_DOWN) {
                return false;
            }
            if (keyCode == KeyEvent.KEYCODE_ENTER) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(getWindow().getDecorView().getRootView().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                return true;
            }
            return false;
        }
    });

可以在运行Android 8.1的一部手机上运行,​​但不能在运行Android 8.0的另一部手机上运行

这可能是什么原因造成的?

0 个答案:

没有答案
相关问题