保持 android 键盘显示
Keep android sof keyboard shown
我在软键盘中添加了 "Go" 按钮,只要我按下它,键盘就会隐藏。如何保持显示?使用此代码显示它不起作用。谢谢
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId== EditorInfo.IME_ACTION_GO){
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
}
return false;
}
我已经为你编辑了答案,如果你错过了 setSingleLine(true) 整个东西将无法工作..我以为你已经添加了,但你可能没有添加 试试这个兄弟:
et1.setHint("testing");
et1.setImeActionLabel("Go", EditorInfo.IME_ACTION_GO);
et1.setSingleLine(true);
et1.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId== EditorInfo.IME_ACTION_GO){
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(et1, InputMethodManager.SHOW_FORCED);
return true;
}
else
return false;
}
} );
如果您希望键盘显示在 activity 的开头,您可以在 activity 标签内的 AndroidManifest.xml 添加下行:
android:windowSoftInputMode="stateVisible"
要解决您的 'GO' 按钮问题,您可以使用以下代码:
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
//imm.hideSoftInputFromWindow(editText.getWindowToken(), 0); //to hide
imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED); //to show
您可以在适合您的任务的任何事件上使用它,例如 TextWatcher's
onTextChanged
、编辑器监听器。
我在软键盘中添加了 "Go" 按钮,只要我按下它,键盘就会隐藏。如何保持显示?使用此代码显示它不起作用。谢谢
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId== EditorInfo.IME_ACTION_GO){
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
}
return false;
}
我已经为你编辑了答案,如果你错过了 setSingleLine(true) 整个东西将无法工作..我以为你已经添加了,但你可能没有添加 试试这个兄弟:
et1.setHint("testing");
et1.setImeActionLabel("Go", EditorInfo.IME_ACTION_GO);
et1.setSingleLine(true);
et1.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId== EditorInfo.IME_ACTION_GO){
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(et1, InputMethodManager.SHOW_FORCED);
return true;
}
else
return false;
}
} );
如果您希望键盘显示在 activity 的开头,您可以在 activity 标签内的 AndroidManifest.xml 添加下行:
android:windowSoftInputMode="stateVisible"
要解决您的 'GO' 按钮问题,您可以使用以下代码:
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
//imm.hideSoftInputFromWindow(editText.getWindowToken(), 0); //to hide
imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED); //to show
您可以在适合您的任务的任何事件上使用它,例如 TextWatcher's
onTextChanged
、编辑器监听器。