isra60
isra60

Reputation: 522

Android webView: Is possible to set numbers keyboard first by default when using input type=text

We have an app that is using webview to present some HTML pages. This HTML page has input type and we were using input-type = number as we only accept numbers with decimal in this field. So the numeric android keypad appeared with the decimal point.

The problem is the Samsung devices updated to Android 4.3. Now the decimal point is missing from the numeric keyboard.

So we need to put the common keyboard in order to have the decimal point. The problem is that the common keypad appears with letters and we want by default that the keypad appears on the numbers part of the keyboard in order to make more user friendly. Like this.

enter image description here

How can we achieve this??

EDIT: Maybe i haven't explain well. The problem is on a HTML page not in an android TextView So all the android:type answers are not useful.

Upvotes: 7

Views: 6042

Answers (2)

Eshan Chattaraj
Eshan Chattaraj

Reputation: 368

You can set for keyboard as InputType number by overriding in class file of the webview laypout you are using: foloow this code

override fun onCreateInputConnection(outAttrs: EditorInfo): InputConnection {
    val inputConnection = BaseInputConnection(this, false)
    outAttrs.imeOptions = EditorInfo.IME_ACTION_DONE
    outAttrs.inputType = EditorInfo.TYPE_CLASS_NUMBER
    return inputConnection
}

It might help you

Upvotes: 0

Erkki Nokso-Koivisto
Erkki Nokso-Koivisto

Reputation: 1275

Subclassing WebView and overriding onCreateInputConnection method does the trick of getting decimal separator into soft keyboard.

Another option is to change HTML input type from "number" to "tel", but that allows user to enter additional characters like "*" and "#".

This seems to be Samsung 4.3 specific issue.

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {

    InputConnection connection = super.onCreateInputConnection(outAttrs);

    if ((outAttrs.inputType & InputType.TYPE_CLASS_NUMBER) == InputType.TYPE_CLASS_NUMBER)
    {
        outAttrs.inputType |= InputType.TYPE_NUMBER_FLAG_DECIMAL;
    }

    return connection;
}

Upvotes: 6

Related Questions