为什么虚拟键盘没有消失?
我有一个非常简单的屏幕,其中有几个 EditText 小部件和一个按钮。在模拟器中,当我单击 EditText 小部件时,会出现一个虚拟键盘。然而,我似乎无法摆脱它。单击屏幕上的空白区域不会使其消失。只需单击虚拟返回键或硬件返回按钮即可使其消失。
我手边没有真正的 Android 手机,所以这只是模拟器的事情还是在实际设备上会这样。如果是,当我单击表单上的其他位置时,我该怎么做才能使虚拟键盘消失?
I have a pretty simple screen with a couple of EditText widgets and a button. In the emulator, when I click on the EditText widget, a virtual keyboard comes up. However, I can't seem to get rid of it. Clicking on an empty space on the screen does not make it go away. Only clicking the virtual Return key or the hardware Back button makes it disappear.
I don't have a real Android phone handy, so is this an emulator only thing or will it be like this on the actual device. If it is, what can I do to make the virtual keyboard go away, when I click elsewhere on the form?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
单击后退按钮。他们敲键盘是一项活动。单击屏幕的随机区域时,没有一种简单的方法可以移除键盘。
Click the back button. They keyboard is an activity. There's not an easy way to remove the keyboard when clicking on a random area of the screen.
AngryHacker,我建议您参考这篇文章 如何关闭/隐藏 android软键盘。
希望这有帮助。
AngryHacker , I woud refer you to this post how to close/hide the android soft keyboard.
Hope this helps.
我认为在模拟器中你可以按 Escape 来隐藏键盘。在真实设备上,键盘上有一个隐藏按钮,或者您可以按用户界面中的其他位置。无论如何,这就是我的 HTC Desire S 上的工作原理。
I think in the emulator you can press Escape to hide the keyboard. On a real device there is a hide button on the keyboard or you can press elsewhere in the ui. That's how it works on my HTC Desire S anyway.
我遇到了这个问题并解决了它。这个问题与我的项目中的
InputMethodManager.SHOW_FORCED
值有关。当我使用SHOW_FORCED
打开键盘时,当我尝试关闭键盘时,键盘没有关闭。例如:
如果您使用上述方式打开键盘,您可以尝试将
SHOW_FORCED
值更改为SHOW_IMPLICIT
值例如:
I lived this problem and i resolved it. This problem is about
InputMethodManager.SHOW_FORCED
value in my project. When i open keypad usingSHOW_FORCED
then when i try to close keypad, keypad was not closing.For Example :
If you use above way to open keypad, you may try to change
SHOW_FORCED
value withSHOW_IMPLICIT
valueFor Example :
我的 Galaxy S2 运行的是 Andriod 2.3.6。
我在登录网站时遇到输入所需文本后键盘无法移开的问题。我发现按下硬件返回按钮确实可以消除虚拟键盘的干扰。但有时它会使网络浏览器返回一页。这令人沮丧,因为这样我就必须重新输入我连接的任何网站的登录信息。希望 Android 4.x 已经解决了其中一些小问题。
I have the Galaxy S2 which is running Andriod 2.3.6.
I was having issues with the keyboard not moving out of the way after entering the needed text when logging into websites. I found that hitting the hardware return button does take the virtual keyboard out of the way. But occassionally it will take the web browser back one page. Which is frustrating because then I have to re-enter the log in info for whatever web site I'm connecting too. Hopefully Android 4.x has solved some of these glitchy issues.
您可以通过执行以下步骤来实现此目的:
通过添加以下属性使父视图(活动的内容视图)可点击且可聚焦
实现 hideKeyboard() 方法
最后,设置 edittext 的 onFocusChangeListener。
来源
You can achieve this by doing the following steps:
Make the parent view(content view of your activity) clickable and focusable by adding the following attributes
Implement a hideKeyboard() method
Lastly, set the onFocusChangeListener of your edittext.
Source