4

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.

  1. User places cursor (using keyboard) on EditText. Because he is using a keyboard the application will not show the softkeyboard.
  2. User presses a SPECIAL key on the keyboard to bring up the softkeyboard.
  3. 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.
  4. 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

solarc
  • 43
  • 4
  • Please elaborate more what you want do you want soft keyboard to go down or not go down. DO you want the key events .. I mean I am not getting any thing from your theory what exactly you want – Abhinav Singh Maurya Sep 16 '11 at 13:22

1 Answers1

2

I think that there are two kind of 'focus' here:

  • EditText focus is necessary to ensure there is exactly one receiver for the keyboard events
  • Keyboard focus, meaning the keyboard is visible and the keys can be pressed.

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.

  • Activity specific

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.

  • System wide

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.

Community
  • 1
  • 1
Laurent'
  • 2,611
  • 1
  • 14
  • 22
  • I understand better now how I should implement this functionality. Thanks for your advice. – solarc Sep 18 '11 at 09:06
  • Start from the SDK SoftKeyboard sample (link in answer) and customize the LatinKeyboardView behavior. – Laurent' Sep 18 '11 at 09:13
  • @solarc are you able to achieve this? If yes let us know what changes required in custom KeyboardView class. Thanks – CodeFury Apr 04 '14 at 10:00