[英]Is it possible to force softkeyboard to show without edittext?
It works fine if I have EditText visible, but once I set its visibilty to GONE or INVISIBLE, the keyboard doesnt show up anymore, eventhough I have edittext declared in main.xml. 如果我可以看到EditText,它可以正常工作,但是即使将main.xml中声明了edittext,但一旦将其可视性设置为GONE或INVISIBLE,键盘就不再显示。 So is it even possible to show keyboard w/o edittext?
因此,甚至可以显示不带edittext的键盘吗?
You can force the Softkeyboard to without edittext as: 您可以强制将Softkeyboard设置为不带edittext,例如:
InputMethodManager im = (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
im.showSoftInput(myView, InputMethodManager.SHOW_FORCED);
Here you go: 干得好:
InputMethodManager inputMngr = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMngr.showSoftInputFromInputMethod(windowToken, flags)
You can get window token on any View by calling view.getWindowToken() . 您可以通过调用view.getWindowToken()在任何View上获取窗口令牌。 Flags can be found in INputMethodManager.
可以在INputMethodManager中找到标志。
Warning: you must close the keyboard yourself when you're done taking input by calling inputMngr.hideSoftInputFromWindow(windowToken, flags) . 警告:完成输入后,必须通过调用inputMngr.hideSoftInputFromWindow(windowToken,flags)关闭键盘。
Note that if you are working in landscape mode, the soft input will create its own text input field ruining all your hard work. 请注意,如果您在横向模式下工作,则软输入将创建其自己的文本输入字段,这会破坏您的所有辛苦工作。 You can prevent this behavior:
您可以防止这种现象:
// This makes us remain invisible when in landscape mode.
setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
Now if you have set up an invisible EditText it will remain as you made it. 现在,如果您设置了不可见的EditText,它将保持原样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.