4
本质上,我试图显示虚拟键盘和收集输入,而不使用可见的EditText
或TextView
。我知道toggleSoftInput
可以用来做到这一点,但我需要使用showSoftInput
,因为我想用TextWatcher
来操纵输入。另外,我使用的引擎是C++,因此我试图尽可能少使用纯java代码,所以我避免了.xml文件。所以这里去...为什么不显示SoftInput显示虚拟键盘?
public class GameActivity extends Activity {
protected GameView view = null;
protected EditText editText;
protected void onCreate(Bundle bundle)
{
super.onCreate(bundle);
view = new GameView(this);
setContentView(view);
editText = new EditText(this);
editText.setCursorVisible(false);
editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
}
public boolean showKeyboard()
{
JniApp.log("showKeyboard() in Java invoked!!!");
editText.requestFocus();
editText.requestFocusFromTouch();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
}
其中showKeyboard()
是我的C++调用java。我已经检查过,以确保editText
获得重点并且是。但是,showSoftInput
返回false。任何帮助将不胜感激。
更新:经过一些调试后,看起来好像requestFocus
返回true,但活动仍然表示view
是当前焦点。