我想知道两件事
如何始终显示软键盘并且不要让它关闭(即使按下后退或OK按钮)?
如何从中获取输入?
我已经尝试过这段代码:
EditText yourEditText= (EditText) findViewById(R.id.ed);
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
有这些变种:
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
imm.toggleSoftInputFromWindow( yourEditText.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
答案 0 :(得分:2)
将android:windowSoftInputMode="stateAlwaysVisible"
用于AndroidManifest.xml
文件
喜欢这样:
<activity android:name=".YourActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateAlwaysVisible" /> // OR stateVisible
如果该活动具有
EditText
,那么何时活动将开始 你的键盘自动打开
如果您想在完成任何操作后仍然打开Keyboad
,请通过 programetically
InputMethodManager imm =
(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInputFromWindow(
linearLayout.getApplicationWindowToken(),
InputMethodManager.SHOW_FORCED, 0);
或强>
显示软键盘
InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(EDITABLE_VIEW,
InputMethodManager.SHOW_IMPLICIT);
或强>
EDITABLE_VIEW
可以是任何关注屏幕的视图,例如
mEditText = (EditText) findViewById(R.id.editText);
InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mEditText ,
InputMethodManager.SHOW_IMPLICIT);
或强>
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInputFromInputMethod(editText.getWindowToken(), 0);