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. So is it even possible to show keyboard w/o edittext?
You can force the Softkeyboard to without edittext as:
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() . Flags can be found in INputMethodManager.
Warning: you must close the keyboard yourself when you're done taking input by calling 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.