Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 254
isra60 Avatar asked Jan 22 '14 10:01

isra60


1 Answers

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;
}
like image 152
Erkki Nokso-Koivisto Avatar answered Nov 06 '22 03:11

Erkki Nokso-Koivisto