Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Soft keyboard in webview - no "next" button to tab between input fields

My soft keyboad doesn't show this button when I focus webview input fields. Don't find anything about special settings to enable this - am I missing something? It doesn't appear in any kind of input field (alpha/numeric).

Android version 4.0.3

Thanks in advance!

like image 257
User Avatar asked May 22 '13 08:05

User


2 Answers

Here is what helped me (Nexus 4 and Nexus 5 with Android 4.4.*), using a custom WebView and overriding EditInfo from onCreateInputConnection():

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;
    }
}
like image 156
aleksey_chugaev Avatar answered Nov 19 '22 11:11

aleksey_chugaev


Thats how its been implemented unfortunately in Android < 4.1

When webkit renders the input fields, it converts them into android.webkit.WebTextView objects which determine how the softkeyboard would look like and below 4.1 I dont think there is a way to be change this or override the ImeOptions set by the WebTextView class

Thats why if you have a pure numeric field, you would see a next button but for other fields you will see "Go" button. So pure numeric I would expect to see it, surprised you dont

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

This is from the webviewclass.java file from webkit

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;

So its clear that number and telephone fields have next. Now I say <4.1 because 4.1 you could probably use and extend WebViewInputConnection from WebViewClassic.java in webkit and hack this to work for text fields, but yeah no documented change from Android, they are sticking to this design, and I havent even tried this, so just speculative hope :D

like image 22
Vrashabh Irde Avatar answered Nov 19 '22 09:11

Vrashabh Irde