隐藏软键盘 [英] Hide Soft Keyboard

查看:188
本文介绍了隐藏软键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够隐藏软键盘响应于点击按钮。我已经看到了关于这个问题的大量帖子,似乎该解决方案是使用 InputMethodManager ,但我一直无法得到它为我工作。按说下面会隐藏软键盘:

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. 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.

我发现电话:

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.

任何想法?

感谢

推荐答案

您可能会想尝试:

InputMethodManager inputManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(editView.getWindowToken(), 0);

这篇关于隐藏软键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆