android强制键盘可见
我的函数,从 onResume() 运行不会导致键盘出现。
我做错了吗?
private void showKeyboard() {
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(txtSearch, InputMethodManager.SHOW_FORCED);
txtSearch.requestFocus();}
My function, run from the onResume() does not cause the keyboard to appear.
Am I doing it wrong?
private void showKeyboard() {
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(txtSearch, InputMethodManager.SHOW_FORCED);
txtSearch.requestFocus();}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
软键盘有时会很棘手。我相信最后一行 txtSearch.requestFocus() 是不必要的,实际上可能会把事情搞砸。通过告诉键盘在 txtSearch 上显示 SHOW_FORCED,您已经告诉它获得焦点。
The soft keyboard can be tricky sometimes. I belive the last line,
txtSearch.requestFocus()
is unnecessary, and could actually be screwing things up. By telling the keyboard to SHOW_FORCED on txtSearch you are already telling it to have focus.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
“在实验时,我实际上并没有得到我想要的东西,直到我意识到我应该有一个模拟器没有硬件键盘的设备:”
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
may help you.
Note that there are Android devices with hardware-keyboards out there.
e.G. GoogleTV devices often have no touchscreen but a hardware-keyboard.
Some are even emulating the touchscreen.
This is relevant if you are developing in an emulator:
http://plainoldstan.blogspot.com/2010/09/android-set-focus-and-show-soft.html
"When experimenting I was not actually getting what I wanted until I realized I should have an emulator device with no hardware keyboard:"