Android键盘未显示在webview的文本框onfocus上

时间:2013-04-25 04:44:59

标签: android android-webview android-keypad

在我的应用程序中,android 键盘未显示在webview的文本框onfocus 中。对此有任何限制吗?我在webview touchlistener中尝试了 webview.requestFocus()方法。但文本框始终是焦点,键盘根本没有显示。

 @Override
public boolean onTouch(View v, MotionEvent event) {
    // TODO Auto-generated method stub
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_UP:
        if (!v.hasFocus()) {
            v.requestFocus();
        }
        break;
}
return false;

}

我已将此侦听器设置为oncreate方法为 webview.setOnTouchListener(this);

如何解决此问题。?

2 个答案:

答案 0 :(得分:0)

我已经在我的onCreate中实现了这个,这似乎解决了它。 它与您拥有的代码基本相同,但在设置onTouchListener之前添加了_webView.requestFocus(View.FOCUS_DOWN);调用。

    _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;
        }
    });

答案 1 :(得分:0)

尝试此操作以打开键盘。

InputMethodManager inputMethodManager = (InputMethodManager) cntx
                .getSystemService(cntx.INPUT_METHOD_SERVICE);
        inputMethodManager.toggleSoftInputFromWindow(
                view.getApplicationWindowToken(),
                InputMethodManager.SHOW_FORCED, 0);
        view.requestFocus();