可以的Andr​​oid的WebView HTML影响键盘或键盘的功能?键盘、功能、oid、Andr

2023-09-05 02:27:13 作者:有些人只会乍然离场

我有一张信用卡报名表一的WebView(标准<输入类型=文本/> 字段)。在不同的Andr​​oid版本,我得到不同的键盘。洁吉似乎没有表现出 $ P $光伏 / 下一步键在窗体中时。

I have a webview with a credit card entry form (with standard <input type="text" /> fields). In different versions of Android I get different keyboards. Kit-Kat seems to not show Prev / Next keys when inside the form.

在网络方面,我有过这个是否有影响? 如果没有, 我建议开发者对于Android的一面? On the web side, do I have any influence over this? If not, what should I recommend to the developer for the Android side?

例无 $ P $光伏 / 下一步:

同样的WebView,与 $ P $光伏 / 下一步:

Same webview, with Prev / Next:

推荐答案

您可以控制​​从web视图键盘,但其他的答案表明,它可能无法与做过的所有键盘工作。尽管如此,我通常会发现最主流的键盘已经实现了我想要的行为。

You can control the keyboard from the WebView, but as other answers suggest it may not work with every keyboard ever made. Despite that, I typically find most mainstream keyboards have implemented the behaviour I want.

本的WebView有一个名为方法 onCreateInputConnection 。您可以挂接到这个方法并添加(和/或删除)标志的 inputType 和/或 imeOptions 。有许多标志提供给您。

The WebView has a method called onCreateInputConnection. You can hook into this method and add (and/or remove) flags to the inputType and/or imeOptions. There are many flags available to you.

退房的EditorInfo选择,特别是IME_FLAG_NAVIGATE_NEXT和IME_FLAG_NAVIGATE_$p$pVIOUS.请参阅下面的使用(它从键盘选项删除preV /下一标志):

Check out the EditorInfo options, in particular IME_FLAG_NAVIGATE_NEXT and IME_FLAG_NAVIGATE_PREVIOUS. See usage below (which removes the prev/next flags from the keyboard options):

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    InputConnection inputConnection = super.onCreateInputConnection(outAttrs);
    outAttrs.imeOptions = outAttrs.imeOptions & ~EditorInfo.IME_FLAG_NAVIGATE_NEXT &
                ~EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS; 
    return inputConnection;
}

另一件事你可以尝试是使用 InputType 标志,以隐藏整个建议吧 TYPE_TEXT_FLAG_NO_SUGGESTIONS 。参见下面的例子(其中增加了不建议标志的输入型):

Another thing you could try is to hide the entire suggestions bar using the InputType flags TYPE_TEXT_FLAG_NO_SUGGESTIONS. See example below (which adds the "no suggestions" flag to the input type):

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    InputConnection inputConnection = super.onCreateInputConnection(outAttrs);
    outAttrs.inputType = outAttrs.inputType | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
    return inputConnection;
}

有可与直接从web视图自定义输入法一出戏许多其他标志。请参阅开发者的链接的网页,你应该希望能够达到你所追求的大多数键盘上的行为。

There are many other flags available to have a play with to customise the IME directly from the WebView. Refer the developer to the linked pages and you should hopefully be able to achieve the behaviour you are after on most keyboards.

 
精彩推荐