简体   繁体   中英

Android soft keyboard showing up on webview

There are a lot of questions about how to display Soft Keyboard in android WebView . I have a problem quite opposite of that.

For some reason the Soft Keyboard keeps showing up every time I click anything (just some text for example) in the WebView content. There are no input fields in the view, nor are there any EditText elements.

This problem exists only when using Android 4.3 (not an issue with older versions or with 4.4).

I have tried most of the solutions I have found and the only way I can get that thing to not appear is using

android:focusableInTouchMode="false" 

in the layout file.

That causes other problems though - now if I add a select field to the HTML file in WebView window - after selection is made an error is produced and focus does not return to the webview (so can't use it any more after that).

01-07 10:59:49.848: W/InputMethodManagerService(287): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@41a0b510 attribute=null, token = android.os.BinderProxy@41771d70

Found a solution. Pretty weird one. I removed the focusableInTouchMode thing from the layout definition and added this to JavaScript in my WebView content:

document.addEventListener('click',function() { 
  document.activeElement.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