[英]Hide Soft Keyboard
I need to be able to hide the soft keyboard in response to clicking a button. 我需要能够隐藏软键盘以响应单击按钮。 I have seen numerous posts on this subject and it seems that the solution is to use the
InputMethodManager
, but I have been unable to get it to work for me. 我已经看过很多关于这个主题的帖子,似乎解决方案是使用
InputMethodManager
,但我无法让它为我工作。 Supposedly the following will hide the soft keyboard: 据说以下将隐藏软键盘:
InputMethodManager inputManager = (InputMethodManager)
getSystemService(INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromInputMethod(editView.getWindowToken(), 0);
However, this is not working for me (can any suggest why?), and even if it did, I want to be able to hide the keyboard regardless of what view has the input, and I may not know what view that is. 但是,这对我不起作用(可以说明为什么?),即使它确实如此,我也希望能够隐藏键盘而不管输入的视图是什么,我可能不知道那是什么视图。
I found that the call: 我发现了电话:
inputManager.toggleSoftInput(0, 0);
will hide the keyboard if it is currently being shown. 如果当前正在显示键盘,则会隐藏键盘。 Unfortunately it will also show it if it is currently hidden.
不幸的是,如果当前隐藏它也会显示它。 So for this to work for me, I would need a way to determine whether it is currently visible.
因此,为了让我能够工作,我需要一种方法来确定它当前是否可见。
Any ideas? 有任何想法吗?
Thanks 谢谢
You might want to try: 您可能想尝试:
InputMethodManager inputManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(editView.getWindowToken(), 0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.