android force keyboard visible

半城伤御伤魂 提交于 2019-12-02 06:22:55

问题


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

回答1:


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.




回答2:


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:"



来源:https://stackoverflow.com/questions/3517704/android-force-keyboard-visible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!