webview中的软键盘 - 输入字段之间没有"下一个"按钮

Ixx*_*Ixx 6 android webview

当我关注webview输入字段时,我的软键盘不显示此按钮.没有找到任何关于特殊设置来启用此功能 - 我错过了什么吗?它不会出现在任何类型的输入字段(字母/数字)中.

Android版本4.0.3

提前致谢!

小智 7

以下是帮助我(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;
    }
}
Run Code Online (Sandbox Code Playgroud)


Sla*_*ast 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"
Run Code Online (Sandbox Code Playgroud)

这是来自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;
Run Code Online (Sandbox Code Playgroud)

所以很明显,下一个数字和电话领域.现在我说<4.1因为4.1你可以在webkit中使用和扩展WebViewClassic.java中的WebViewInputConnection并且将其用于文本字段,但是没有记录来自Android的更改,他们坚持这个设计,我甚至没有试过这个,所以只是猜测希望:D