本文介绍了在 WebView 中点击表单字段不显示软键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了自己的 WebView 并设置了 WebChromeClient 和 WebViewClient 对象.当我启动此 WebView 时,HTML 表单字段会在我触摸它们时做出反应(出现光标),但它们不会被选中,软键盘也不会启动.如果我使用轨迹球选择表单并按下它,键盘会出现.

I created my own WebView and set the WebChromeClient and WebViewClient objects. When I start this WebView, the HTML form fields react when I touch them (a cursor appears), but they do not get selected, nor does the soft keyboard start. If I use the trackball to choose the form and press it, the keyboard does appear.

我尝试将 myWebview.requestFocusFromTouch() 称为 this answer 建议,但它返回 false 并且没有帮助.

I tried to call myWebview.requestFocusFromTouch() as this answer suggested, but it returns false and doesn't help.

推荐答案

http://code.google.com/p/android/issues/detail?id=7189

这里有一个修复,以防其他人不清楚.

Here is a fix in case other were not clear.

    webview.requestFocus(View.FOCUS_DOWN);
    webview.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                case MotionEvent.ACTION_UP:
                    if (!v.hasFocus()) {
                        v.requestFocus();
                    }
                    break;
            }
            return false;
        }
    });

这篇关于在 WebView 中点击表单字段不显示软键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 20:08