ang*_*ang 16 android android-softkeyboard android-edittext
我正在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?
现在,我能看到的唯一方法是创建我自己的软键盘实现(即从头开始构建).不期待那样!
以下代码对我有用:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput (InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
Run Code Online (Sandbox Code Playgroud)
当我按下“菜单”按钮时,我在onKeyUp处理程序中使用此代码。
visibility="invisible"您可以android:alpha="0"在 EditText 上设置而不是使用。所以你仍然需要一个 EditText 但它不可见,你可以通过一个软键盘从软键盘获取输入onKeyListener()
您可以使用以下命令强制显示软键盘:
InputMethodManager im = (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
im.showSoftInput(myView, InputMethodManager.SHOW_FORCED);
| 归档时间: |
|
| 查看次数: |
7502 次 |
| 最近记录: |