简体   繁体   中英

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.

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. 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() . Search your code base for the blur() pattern to see if that is what is happening for you.

To fix, try something like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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