0

在我的应用程序中,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);

我该如何解决这个问题。?

4

2 回答 2

0

I have implemented it like this in my onCreate and this seems to fix it. It's basically the same code you have but with the _webView.requestFocus(View.FOCUS_DOWN); call added before setting the onTouchListener.

    _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;
        }
    });
于 2013-04-25T05:23:01.953 回答
0

Try this to open the keyboard.

InputMethodManager inputMethodManager = (InputMethodManager) cntx
                .getSystemService(cntx.INPUT_METHOD_SERVICE);
        inputMethodManager.toggleSoftInputFromWindow(
                view.getApplicationWindowToken(),
                InputMethodManager.SHOW_FORCED, 0);
        view.requestFocus();
于 2013-04-25T05:25:12.840 回答