【问题标题】:Android webView: Is possible to set numbers keyboard first by default when using input type=textAndroid webView:使用输入类型=文本时,默认情况下可以先设置数字键盘
【发布时间】:2014-02-12 09:14:38
【问题描述】:

我们有一个应用程序使用 webview 来呈现一些 HTML 页面。 这个 HTML 页面有输入类型,我们使用 input-type = number 因为我们只接受在这个字段中带有小数的数字。 所以数字android小键盘出现了小数点。

问题在于三星设备已更新至 Android 4.3。现在数字键盘上缺少小数点。

所以我们需要把普通键盘放到小数点上。问题是常见的小键盘以字母出现,我们希望默认小键盘出现在键盘的数字部分,以使用户更加友好。像这样。

我们怎样才能做到这一点??

编辑:也许我解释得不好。问题出在 HTML 页面上,而不是在 android TextView 中 所以所有的 android:type 答案都没有用。

【问题讨论】:

标签: android validation webview android-keypad numeric-keypad


【解决方案1】:

继承 WebView 并覆盖 onCreateInputConnection 方法可以将小数分隔符放入软键盘。

另一种选择是将 HTML 输入类型从“数字”更改为“电话”,但允许用户输入额外的字符,如“*”和“#”。

这似乎是三星 4.3 特有的问题。

@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;
}

【讨论】:

    【解决方案2】:

    您可以通过在您正在使用的 webview 布局的类文件中覆盖来将键盘设置为 InputType 编号:遵循此代码

    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
    }
    

    也许对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-29
      • 2011-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-14
      相关资源
      最近更新 更多