我正在Android中创建一个简单的打字游戏.我从物理键盘输入输入没有问题,但现在我试图让软键盘在没有EditText的情况下出现.到目前为止,我尝试过以下方法:
1.具有visibility ="invisible"的EditText和此行:
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(keyboard_edittext, InputMethodManager.SHOW_FORCED); // SHOW_IMPLICIT also failed
Run Code Online (Sandbox Code Playgroud)
2.这条线在onCreate():
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
Run Code Online (Sandbox Code Playgroud)
这个方法实际上在屏幕的底部10%显示了一个空的白色框而不是键盘,但是当我现在运行时它什么也没做.
3.另外两行onCreate():
InputMethodManager m = (InputMethodManager)this.getSystemService (Context.INPUT_METHOD_SERVICE); m.toggleSoftInput(0, InputMethodManager.SHOW_IMPLICIT);
Run Code Online (Sandbox Code Playgroud)
任何这些都没有运气.是否可以显示软键盘(然后使用onKeyUp/ onKeyDown)而不关注EditText?
现在,我能看到的唯一方法是创建我自己的软键盘实现(即从头开始构建).不期待那样!