I\'m creating a simple typing game in Android. I have no problem getting input from the physical keyboard, but now I\'m trying to get the soft keyboard to appear without the
Instead of using visibility="invisible"
you can set android:alpha="0"
on your EditText.
So you still need a EditText but it is not visible and you can get the input from the softkeyboard by an onKeyListener()
The following code works for me:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput (InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
I use this code in a onKeyUp handler when I press the "menu" button.
You can force the Softkeyboard to be shown by using:
InputMethodManager im = (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
im.showSoftInput(myView, InputMethodManager.SHOW_FORCED);
Make sure to enable the soft keyboard for your view:
setFocusable(true);
setFocusableInTouchMode(true);
Then call:
InputMethodManager mgr = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT);
Note that if you are working in landscape mode, the soft input will create its own text input field ruining all your hard work. You can prevent this behavior:
// This makes us remain invisible when in landscape mode.
setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
Now if you have set up an invisible EditText it will remain as you made it.