簡體   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