6

当我关注 webview 输入字段时,我的软键盘不显示此按钮。找不到任何有关启用此功能的特殊设置的信息-我是否遗漏了什么?它不会出现在任何类型的输入字段(字母/数字)中。

安卓版本 4.0.3

提前致谢!

4

2 回答 2

8

以下是帮助我的方法(Nexus 4 和 Nexus 5 与 Android 4.4.*),使用自定义 WebView 并从 onCreateInputConnection() 覆盖 EditInfo:

private static class CustomWebView extends WebView {

    public CustomWebView(Context context) {
        super(context);
    }

    @Override
    public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
        InputConnection inputConnection = super.onCreateInputConnection(outAttrs);
        if (outAttrs != null) {
            // remove other IME_ACTION_*
            outAttrs.imeOptions &= ~EditorInfo.IME_ACTION_GO;
            outAttrs.imeOptions &= ~EditorInfo.IME_ACTION_SEARCH;
            outAttrs.imeOptions &= ~EditorInfo.IME_ACTION_SEND;
            outAttrs.imeOptions &= ~EditorInfo.IME_ACTION_DONE;
            outAttrs.imeOptions &= ~EditorInfo.IME_ACTION_NONE;
            // add IME_ACTION_NEXT instead
            outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT;
        }
        return inputConnection;
    }
}
于 2014-07-04T04:29:22.510 回答
6

不幸的是,这就是它在 Android < 4.1 中的实现方式

当 webkit 呈现输入字段时,它将它们转换为android.webkit.WebTextView确定软键盘外观的对象,并且低于 4.1 我不认为有办法改变它或覆盖由 WebTextView 类设置的 ImeOptions

这就是为什么如果您有一个纯数字字段,您会看到一个下一步按钮,但对于其他字段,您会看到“开始”按钮。如此纯数字,我希望看到它,令您惊讶的是

<input type="text" name="..." .... /> ----> on the keyboard you see "Go"
<input type="number" name="..." .... /> ----> on the keyboard you see "Next"

这是来自 webkit 的 webviewclass.java 文件

case WebTextView.NORMAL_TEXT_FIELD:
                    break;
                case WebTextView.TEXT_AREA:
                    inputType |= InputType.TYPE_TEXT_FLAG_MULTI_LINE
                            | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
                            | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT;
                    action = EditorInfo.IME_ACTION_NONE;
                    break;
                case WebTextView.PASSWORD:
                    inputType |= EditorInfo.TYPE_TEXT_VARIATION_WEB_PASSWORD;
                    break;
                case WebTextView.SEARCH:
                    action = EditorInfo.IME_ACTION_SEARCH;
                    break;
                case WebTextView.EMAIL:
                    // inputType needs to be overwritten because of the different text variation.
                    inputType = InputType.TYPE_CLASS_TEXT
                            | InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS;
                    break;
                case WebTextView.NUMBER:
                    // inputType needs to be overwritten because of the different class.
                    inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_NORMAL
                            | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_FLAG_DECIMAL;
                    // Number and telephone do not have both a Tab key and an
                    // action, so set the action to NEXT
                    break;

所以很明显,号码和电话字段有下一个。现在我说 <4.1,因为 4.1 您可能可以在 webkit 中使用和扩展 WebViewInputConnection 从 WebViewClassic.java 并破解它以适用于文本字段,但是是的,Android 没有记录在案的变化,他们坚持这种设计,我什至没有尝试过,所以只是投机的希望:D

于 2013-07-29T17:14:25.160 回答