Android webView touchEvents

时间:2016-02-12 19:47:44

标签: android webview android-softkeyboard ontouchlistener ontouchevent

I have a webapp I am trying to interface with android. It is very easy to get a webview to display the page, however the page uses an on screen keyboard. If only one input was on a page, it would be easy to set

android:focusableInTouchMode="false" 

in the webview, however there are a few places where multiple inputs are present, and this disables the ability to select any them (the first one on the page is automatically selected).

Would it work to maybe extend and override a webView to be able to select an input but not open the softKeyboard?

I have also looked at this example, however I don't think that will work with a webview.

EDIT:

To help clarify, i can just override with myWebView.setOnTouchListener(...), and have done so in test, this is great as it does not allow the softKeyboard to show, however it also does not let anything else happen ie. input selection. Ideally there would be a happy medium where everything happens except the softKeyboard appearing. (yes I have tried other methods such as

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

1 个答案:

答案 0 :(得分:0)

我觉得我的问题有些模糊,因为在我看了几个小时后,我的智慧结束了。

我的最终目标是能够显示带有多个输入字段的屏幕键盘的网页。问题是只要焦点在输入字段上就会显示android softKeyboard。

我尝试了多个解决方法,问题中列出的一个没有用,因为我无法选择任何输入,因为没有注册触摸命令。

我尝试覆盖onTouch,但键盘会在“快速”后显示。触摸,所以不可能有默认行为,仍然拦截和禁用键盘。

解决我的问题的解决方案是扩展WebView类,然后覆盖' onCreateInputConnection'。这是android解释'类型' html输入字段。问题是html没有' null'为此输入,因此android将始终根据输入类型显示某种键盘。然而,Android确实有一个空输入类型,它告诉键盘这里不需要输入。

 @Override
 public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    BaseInputConnection fic = new BaseInputConnection(this, true);
    outAttrs.actionLabel = null;
    outAttrs.inputType = InputType.TYPE_NULL;
    return fic;
}

这个覆盖方法是我的webview完全禁用所有文本字段输入所需的全部方法。

注意:这也会禁用附加的硬件键盘输入...在我的情况下不是问题,但我有兴趣了解一下那里的工作。