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 EditText. So far, I've tried the following:
1. EditText with visibility="invisible" and this line:
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(keyboard_edittext, InputMethodManager.SHOW_FORCED); // SHOW_IMPLICIT also failed
2. This line in the onCreate()
:
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
This method actually displayed an empty white box across the bottom 10% of the screen but not the keyboard, although when I run it now it does nothing.
3. Another two lines in the onCreate()
:
InputMethodManager m = (InputMethodManager)this.getSystemService (Context.INPUT_METHOD_SERVICE); m.toggleSoftInput(0, InputMethodManager.SHOW_IMPLICIT);
No luck on any of these. Is it even possible to display the soft keyboard (and then use onKeyUp
/onKeyDown
) without focusing on an EditText?
Right now, the only way I can see is to approach this is to create my own implementation of the soft keyboard (i.e. build it from scratch). Not looking forward to that!