Manipulating fields in a WebView

from the CommonsWare Community archives

At December 28, 2018, 3:50pm, Raptor asked:

Hello,

I have a screen where I have a WebView and in the received page I get a handful of fields, including “EditTexts” and some calendar fields. The problem is that whenever a calendar field is clicked, the keyboard pops up. I would like to somehow determine what kind of field is clicked in the WebView and based on that, display or hide the keyboard.

Is there any way to do that?

Thanks!


At December 28, 2018, 4:06pm, mmurphy replied:

Presumably those are based on an HTML <input> element, one that WebView thinks involves a keyboard.

I would like to somehow determine what kind of field is clicked in the WebView and based on that, display or hide the keyboard.

It might be simpler to switch to some other calendar library for the Web content, or to contact the developers of whatever calendar you are using and asking them about this keyboard issue.

You might research whether there is something that could go on the calendar <input> element that would suppress the keyboard.

Otherwise, at best, you would need to modify the page to have some JavaScript that gets triggered on clicks of these calendars. In principle, that JavaScript could call out to Java, where you could use InputMethodManager to hide the input method editor. However, I would expect that this would cause a flicker, as the input method editor appears then disappears. I have no idea if there is some way to tell WebView in Java to not show the input method editor.

And if this is not a page that you control, AFAIK you are completely out of luck.


At December 28, 2018, 4:12pm, Raptor replied:

So the best case scenario would be to contact whoever is in charge of the page that my WebView is loading and let them handle it, with the added hint that probably a solution might involve the element. The other solution sounds complicated, like I thought.

Cool, thank you!


At December 28, 2018, 5:14pm, mmurphy replied:

IMHO, yes, assuming that is practical (e.g., the person in charge of the page works at the same firm that you do). This keyboard thing is unlikely to be unique to WebView — I would expect some browsers to exhibit the same sort of behavior. Collectively, you will need to decide how best to handle it.

Good luck! You might need it! :grin:


At December 30, 2018, 8:06pm, Raptor replied:

Well, luckily for me, this was more of a curiosity (if in principle it can be done) rather than something imperative (it was something that I found out and wanted to know if it can be solved, not something that my company asked me to solve).