Setting explicit focus on the input method editor / softkeyboard in android

I am working with the input method editor of the standard Android keyboard. I show the on-screen keyboard on my Android emulator after clicking a specific key and focus on the edittext. My goal is to set the focus on the on-screen keyboard after it appears on the screen. I know that soft keyboards are usually used for input without a hard keyboard at all, but in my case the application that I am developing needs this function because it will work on a user device and the source for Android will be changed for user functions. Does anyone know how to solve this problem? Is it possible that the touch mode does not allow you to set focus on the keyboard?

EDIT: Clarification

Sorry for being ambiguous. Basically I need the following functions from the soft keyboard in the following case.

  • The user places the cursor (using the keyboard) in the EditText. Since it uses a keyboard, the application will not display a soft keyboard.
  • The user presses the SPECIAL key on the keyboard to call up the on-screen keyboard.
  • Focus should change using EditText to SOFTKEYBOARD, which means that the user must be able to move around and select keys on the keyboard using a hard keyboard. Of course, this means that key events must be added to the standard soft keyboard.
  • After the user selects the key, he presses the enter key (for example), and the key symbol should appear in the editor.

Currently, the problem is that when I raise the soft keyboard, FOCUS stays on edittext. I would like to know if it is even possible to focus on the soft keyboard and move on using the hard keyboard. Like I told you before this is custom functionality. Perhaps I am solving this problem incorrectly, and a simple pop-up window with a keyboard view is enough.

Loren I think that you are right in the sense that the standard software keyboard is implemented as a service and does not comply with the rules of regular presentations.

Any advice is appreciated.

thanks

+4
source share
1 answer

I think there are two kinds of “focus” here:

  • Pressing EditText is necessary to provide exactly one receiver for keyboard events.
  • The keyboard focus, that is, the keyboard is visible and the keys can be pressed.

As far as I understand, in android only FocusText gets focus. The keyboard works in the service and receives touch events thanks to the special Insets class.

If you only need to increase the visibility of your keyboard, you should try the answers to this question .

EDIT

I think there are two ways to do this, depending on whether you want this keyboard to be activity specific or accessible everywhere.

  • Action specificity

As far as I understand, the inputmethodservice method, which is responsible for showing the keyboard, will not allow you to achieve this.

My best advice is that you create a specialized keyboard view that has this "focus key" feature (an extended keyboard would be a good starting point).

You can change the keyboard visibility (using View.VISIBLE and View.GONE) so that it looks and disappears.

Then you must enter your own behavior to select the key with focus and move it accordingly.

In your activity, you will also need to remember the last EditText in which it would be concentrated in order to send him text or keyCodes.

  • System as a whole

If you want this behavior to be available throughout the system, you must provide your inputmethodservice . I advise you to take a look at this post as well as the SoftKeyboard sample in the SDK.

Please note that you also need to create your own KeyboardView, as described above, but without having to remember the focus of the EditText.

+2
source

All Articles