When a person clicks on the EditText he has a virtual keyboard. It has all sorts of buttons, except for letters and numbers, for example, the Enter button.

I need to intercept or prohibit clicking on these buttons. Buttons like "language change" or even worse - long pressing the "language change" button a dialog box appears where you can get into the settings.

This is how I intercept the Enter key.

editText.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View view, int keyCode, KeyEvent keyEvent) { if ((keyEvent.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { return true; } return false; } }); 

For the rest I can not.

  • Do you need to prohibit entering certain characters or switching to settings? - ProkletyiPirat
  • Go to settings. And this is either intercepting to press this button, or remove this button altogether from the keyboard. - Moby
  • I'm just wondering, why ban? the user will still find a way to do it. And add yourself problems. What problem do you solve? - KoVadim

1 answer 1

In applications of the on-screen keyboard, pressing your own buttons (be it a setting, T9 on / off, language change) does not trigger the keyboard button press event, since the keyboard developer determines the set of these "additional" buttons, not the Android system. You, for example, can create your own virtual keyboard for use in your application, and make it appear when the focus falls on EditText, previously canceling the display of the standard keyboard.
Get a link to the View, which fell focus can (I do not remember how to vskidku, but I can).

  • view.setOnFocusChangeListener (OnFocusChangeListener listener); - ProkletyiPirat