繁体   English   中英

是否可以强制软键盘在没有edittext的情况下显示?

[英]Is it possible to force softkeyboard to show without edittext?

如果我可以看到EditText,它可以正常工作,但是即使将main.xml中声明了edittext,但一旦将其可视性设置为GONE或INVISIBLE,键盘就不再显示。 因此,甚至可以显示不带edittext的键盘吗?

您可以强制将Softkeyboard设置为不带edittext,例如:

InputMethodManager im = (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
im.showSoftInput(myView, InputMethodManager.SHOW_FORCED);

干得好:

InputMethodManager inputMngr = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMngr.showSoftInputFromInputMethod(windowToken, flags)

您可以通过调用view.getWindowToken()在任何View上获取窗口令牌。 可以在INputMethodManager中找到标志。

警告:完成输入后,必须通过调用inputMngr.hideSoftInputFromWindow(windowToken,flags)关闭键盘。

请注意,如果您在横向模式下工作,则软输入将创建其自己的文本输入字段,这会破坏您的所有辛苦工作。 您可以防止这种现象:

// This makes us remain invisible when in landscape mode.
setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);

现在,如果您设置了不可见的EditText,它将保持原样。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM