2

我的函数,从 onResume() 运行不会导致键盘出现。

我做错了吗?

private void showKeyboard() {
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(txtSearch, InputMethodManager.SHOW_FORCED);
txtSearch.requestFocus();}
4

2 回答 2

0

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); 可以帮助你。请注意,那里有带有硬件键盘的 Android 设备。eG GoogleTV 设备通常没有触摸屏,只有硬件键盘。有些甚至在模仿触摸屏。

如果您在模拟器中开发,这很重要:

http://plainoldstan.blogspot.com/2010/09/android-set-focus-and-show-soft.html

“在进行实验时,我实际上并没有得到我想要的,直到我意识到我应该有一个没有硬件键盘的仿真器设备:”

于 2011-07-11T09:04:57.927 回答
0

软键盘有时会很棘手。我相信最后一行,txtSearch.requestFocus()是不必要的,实际上可能把事情搞砸了。通过在 txtSearch 上告诉键盘 SHOW_FORCED 你已经告诉它有焦点。

于 2010-08-19T00:51:26.933 回答