是否可以强制软键盘显示没有edittext?

时间:2012-07-01 11:31:50

标签: android android-softkeyboard

如果我有EditText可见,它工作正常,但是一旦我将其可见性设置为GONE或INVISIBLE,键盘就不再出现了,尽管我在main.xml中声明了edittext。那么甚至可以显示没有编辑文本的键盘吗?

3 个答案:

答案 0 :(得分:0)

您可以在不使用edittext的情况下强制使用Softkeyboard:

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

答案 1 :(得分:0)

你走了:

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

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

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

答案 2 :(得分:0)

请注意,如果您在横向模式下工作,则软输入将创建自己的文本输入字段,从而破坏您的所有辛勤工作。您可以阻止此行为:

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

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

相关问题