Android 在编辑文本中输入文本后无法隐藏软键盘
我有一个布局,有5个编辑文本,3个单选按钮和两个按钮。在5个编辑文本之后,我有3个单选按钮,然后是2个按钮。在第五次编辑文本中输入文本后,由于软键盘,我无法看到单选按钮和普通按钮。输入第五个编辑文本后,如何禁用该软键盘?有人能帮我解决这个问题吗…请尝试下面的代码片段来隐藏/关闭软键盘Android 在编辑文本中输入文本后无法隐藏软键盘,android,Android,我有一个布局,有5个编辑文本,3个单选按钮和两个按钮。在5个编辑文本之后,我有3个单选按钮,然后是2个按钮。在第五次编辑文本中输入文本后,由于软键盘,我无法看到单选按钮和普通按钮。输入第五个编辑文本后,如何禁用该软键盘?有人能帮我解决这个问题吗…请尝试下面的代码片段来隐藏/关闭软键盘 getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN ); 只需使用: Inpu
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
);
只需使用:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
每当您想隐藏软键盘时
在您的情况下:
让您的第五个EditText
成为et
。。
然后使用:
if(!et.toString().equals(null)){
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
或
您可以通过以下链接检测第五个
EditText
是否聚焦,然后相应地采取行动(即,如果EditText
聚焦,则使用上述方法隐藏键盘:或
检测软键盘上的
Done
按键事件:按下
DONE
按钮时,键盘将自动关闭。但如果您想在按下DONE
按钮时执行海关操作,请参阅以下内容:
et= (EditText) findViewById(R.id.edit_text);
et.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
// do your stuff here
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
return false;
}
});
希望这有帮助 隐藏键盘不是个大问题,但你需要确认“什么时候?” 你需要打电话
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edittext.getApplicationWindowToken(), 0);
用于隐藏软键盘
尝试在edittext xml文件中添加android:imeOptions=“actionNext”,然后
edittext.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
boolean flag= false;
if (i == EditorInfo.IME_ACTION_NEXT) {
flag= true;
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edittext.getApplicationWindowToken(), 0);
}
return flag;
}
});
此代码将在单击键盘中的下一步时隐藏软键盘在上次编辑tetx中输入文本后隐藏软键盘?我应用了InputMethodManager imm=(InputMethodManager)getSystemService(Context.INPUT\u METHOD\u SERVICE);imm.hideSoftInputFromWindow(country.getWindowToken(),0);最后一个编辑文本值的代码我将测试第二个,您在此处放置了什么当然,如果您在某个地方卡住了,请告诉我!实际上,在一些手机的软键盘上,有一个键按钮在输入所有值后完成。是的,您可以检测到“完成键”的键事件。按照下面的链接:@yamunaI对我的测试手机的done键感到困惑,所以在输入所有值后,我可以使用done按钮,这样它就隐藏了软键盘,所以我对此没有问题。所有手机都将完成选项?理想情况下,你不应该这样做,因为这取决于用户是否完成编辑。因此,用户不应该是关闭键盘的人吗?
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edittext.getApplicationWindowToken(), 0);
edittext.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
boolean flag= false;
if (i == EditorInfo.IME_ACTION_NEXT) {
flag= true;
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edittext.getApplicationWindowToken(), 0);
}
return flag;
}
});