abr*_*sze -2 keyboard android android-keypad android-edittext window-soft-input-mode
我想知道 2 件事
如何始终显示软键盘并且不让它关闭(即使按下后退或确定按钮)?
我怎样才能从中获得输入?
我已经尝试过这段代码:
EditText yourEditText= (EditText) findViewById(R.id.ed);
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
Run Code Online (Sandbox Code Playgroud)
具有这些变体:
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);imm.toggleSoftInputFromWindow( yourEditText.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);用于android:windowSoftInputMode="stateAlwaysVisible"归档AndroidManifest.xml
像这样:
<activity android:name=".YourActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateAlwaysVisible" /> // OR stateVisible
Run Code Online (Sandbox Code Playgroud)
如果该活动有
EditText那么每当活动将启动您的键盘自动打开
如果您想Keyboad在使用完成任何操作后仍然打开,请通过编程方式执行此操作
InputMethodManager imm =
(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInputFromWindow(
linearLayout.getApplicationWindowToken(),
InputMethodManager.SHOW_FORCED, 0);
Run Code Online (Sandbox Code Playgroud)
或者
显示软键盘
InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(EDITABLE_VIEW,
InputMethodManager.SHOW_IMPLICIT);
Run Code Online (Sandbox Code Playgroud)
或者
EDITABLE_VIEW可以是任何聚焦在屏幕上的视图,例如
mEditText = (EditText) findViewById(R.id.editText);
InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mEditText ,
InputMethodManager.SHOW_IMPLICIT);
Run Code Online (Sandbox Code Playgroud)
或者
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInputFromInputMethod(editText.getWindowToken(), 0);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4224 次 |
| 最近记录: |