gpt4 book ai didi

android - 隐藏软键盘

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:54:55 25 4
gpt4 key购买 nike

我需要能够隐藏软键盘以响应单击按钮。我看过很多关于这个主题的帖子,似乎解决方案是使用 InputMethodManager,但我无法让它为我工作。据推测,以下将隐藏软键盘:

  InputMethodManager inputManager = (InputMethodManager) 
getSystemService(INPUT_METHOD_SERVICE);

inputManager.hideSoftInputFromInputMethod(editView.getWindowToken(), 0);

但是,这对我不起作用(有什么建议可以解释为什么吗?),即使它起作用了,我也希望能够隐藏键盘,而不管哪个 View 有输入,而且我可能不知道那个 View 是什么是。

我发现调用:

inputManager.toggleSoftInput(0, 0);

将隐藏键盘(如果当前正在显示)。不幸的是,如果它当前处于隐藏状态,它也会显示它。因此,为了让这对我有用,我需要一种方法来确定它当前是否可见。

有什么想法吗?

谢谢

最佳答案

你可能想试试:

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

关于android - 隐藏软键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3858362/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com