I am working with Android’s standard softkeyboard input method editor. I am showing the softkeyboard on my android emulator after a specific key has been pressed and an edittext view has focus. My purpose is to set the focus on the softkeyboard after it appears on screen. I know softkeyboards are generally used for input without a hard keyboard at all, but in my case the app I am developing needs this functionality as it will run on a custom device and android’s source is being modified for custom functionality. Does anybody have any idea on how to tackle this problem? Could it be possible that touch mode does not allow to set focus on the keyboard?
EDIT: Clarification
Sorry for being ambiguous. Basically I require the following functionality from the softkeyboard in the following case.
- User places cursor (using keyboard) on EditText. Because he is using a keyboard the application will not show the softkeyboard.
- User presses a SPECIAL key on the keyboard to bring up the softkeyboard.
- Focus should change frrom the EditText to the SOFTKEYBOARD, meaning that the user should be able to navigate and select keys on the softkeyboard using the hard keyboard. Of course this means that key events should be added to the standard softkeyboard.
- After user chooses a key he presses enter (for example) and the key character should appear on the edittext.
Right now the problem is that when i bring up the softkeyboard the FOCUS remains on the edittext. I would like to know if it is even possible to place the focus on the softkeyboard and move on it using a hard keyboard. As i told you before this is custom functionality. Maybe I am tackling this problem the wrong way and a simple popup window with a keyboard view would suffice.
Lauren I think you are right in the sense that the standard softkeyboard is implemented as a service and does not follow the rules of regular views.
Any advice is appreciated.
Thanks
I think that there are two kind of ‘focus’ here:
To my understanding, in android, only the EditText gets the focus. The keyboard runs in a service and gets touch events thank to a special Insets class.
If all you need is to force your keyboard visibility, you should try answers from this question.
EDIT
I think there are two ways to do so depending on if you want this keyboard to be specific to an activity or available everywhere.
To my understanding, the inputmethodservice that is responsible for showing the keyboardview will not allow you to achieve this.
My best advice is that you create a specialized keyboard view that have this “focusable keys” feature (extending keyboardview would be a good starting point).
You can change the keyboard visibility (using View.VISIBLE and View.GONE) to make it appear and disappear.
Your should then code your own behavior to highlight the key with the focus and move it accordingly.
Your activity will also have to remember the last EditText that had focus to send text or keyCodes to it.
If you need this behavior to be available everywhere on the system, then you must provide your own inputmethodservice. I advice you take a look at this post as well as the SoftKeyboard sample in the SDK.
Please note that you will also need to create a custom KeyboardView as described above, but without the need to remember the EditText focus.