首页 > 解决方案 > Android - 电子邮件 InputField 不接受用户输入

问题描述

我有一个WebView加载远程网页(这个),其 HTML 不在我的控制范围内。在该页面上,有一个电子邮件字段是必需的,并且可能具有电子邮件验证。

当我点击该电子邮件字段输入电子邮件地址时,Android 的键盘会出现,但当我开始输入时,它不会在其中写入任何内容。还有一些其他字段,它们也是必需的,并且可能已经过验证,但它们可以很好地输入。只有电子邮件字段会导致此问题。

该电子邮件字段在 Android Firefox 和 Google Chrome 中运行良好。

我的 Javascript 已启用,WebView但它什么也没做。有谁知道我怎样才能让那个电子邮件字段接受输入?

标签: androidandroid-webview

解决方案


您的键盘不支持WebView. 所以你需要强制WebView打开默认键盘。

您必须WebView通过扩展WebView类进行自定义。覆盖其onCreateInputConnection()方法:

import android.content.Context
import android.util.AttributeSet
import android.view.inputmethod.BaseInputConnection
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputConnection
import android.webkit.WebView

class QWebView : WebView
{
    constructor(context: Context?) : super(context)
    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int, privateBrowsing: Boolean) : super(context, attrs, defStyleAttr, privateBrowsing)

    override fun onCreateInputConnection(outAttrs: EditorInfo?): InputConnection
    {
        return BaseInputConnection(this, false)
    }
}

推荐阅读