Block physical keyboard input in EditText

只谈情不闲聊 提交于 2019-12-04 17:54:23

Finally got it!
Code:

editText.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            return true;
        }
    });

Explanation:
Returning true will tell the listener that I've already handled the hardware keyboard input. Based on Android documentation (http://developer.android.com/reference/android/view/View.OnKeyListener.html)

View.OnKeyListener: Interface definition for a callback to be invoked when a hardware key event is dispatched to this view. The callback will be invoked before the key event is given to the view. This is only useful for hardware keyboards; a software input method has no obligation to trigger this listener.

onKey(View v, int keyCode, KeyEvent event) Called when a hardware key is dispatched to a view.

You could try these according to what you want in your xml layout

android:longClickable="false"
android:clickable="false"    
android:cursorVisible="false"
android:editable="false"

Then make the edittext show what the user typed through the keyboard you made in the app.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!