简体   繁体   English

防止android webview软键盘失去焦点

[英]Prevent android webview soft keyboard to lost focus

I have a problem since a long time and I have not find a way of solving it. 很长一段时间以来,我一直遇到问题,但找不到解决方法。

My app as a webview that loads an url where the user can fill certain text inputs, also, the app produces sounds in certain situations(to help/assist the users), the problem is that, sometimes when the user is writing in an input and some sound is triggered the soft keyboard hides because the input lost its focus. 我的应用程序是作为Web视图加载的URL,用户可以在其中填充特定的文本输入,此外,该应用程序在某些情况下会发出声音(以帮助/帮助用户),问题是,有时当用户在输入中编写内容时并触发了一些声音,软键盘隐藏了,因为输入失去了焦点。

This is quite annoying to the users because they have to touch the input again to continue writing. 这对于用户来说非常烦人,因为他们必须再次触摸输入才能继续书写。

Any ideas about how to solve it? 关于如何解决的任何想法?

I was confused on this same issue but I learned that it is common practice to call search.blur() (assuming we are talking about a search text input field) when a window.resize event is triggered for desktop, but sometimes that same code causes issues on mobile because the virtual keyboard triggers a resize event as well. 我在同一问题上感到困惑,但是我了解到在为桌面触发window.resize事件时调用search.blur() (假设我们正在谈论搜索文本输入字段)是一种常见的做法,但有时代码相同导致移动设备出现问题,因为虚拟键盘也会触发调整大小事件。 If this is the case, you may have to use something like modernizr to determine if you are in a mobile device context and if so don't call that search.blur() . 在这种情况下,您可能必须使用modernizr之类的方法来确定您是否在移动设备环境中,如果不这样做,请不要调用该search.blur() Search your code base for the blur() pattern to see if that is what is happening for you. 在您的代码库中搜索blur()模式,以查看是否正在发生这种情况。

To fix, try something like this: 要解决此问题,请尝试以下操作:

window.onresize = function () {
  if (!isMobile) {
      search.blur()
  }
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM