Android:将键盘隐藏在覆盖的“完成”中EditText 的按键
我使用了一些 Android 代码来覆盖 EditText 字段中的“完成”按钮:
myEditField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
mySubroutine();
return true;
}
return false;
}
});
激活该字段会调用键盘,然后按“完成”即可成功评估 mySubroutine()。但是,当我按“完成”时,键盘不再消失。如何将这种默认行为恢复到例程中?
I have used a bit of Android code to override the "Done" button in my EditText field:
myEditField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
mySubroutine();
return true;
}
return false;
}
});
Activating the field calls up the keyboard, and pressing "Done" evaluates mySubroutine() successfully. However, the keyboard no longer goes away when I press "Done". How do I restore this default behaviour to the routine?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为什么不:
在处理代码后返回 false 即可。这可以解释为无论您的代码 (mySubroutine()) 做什么,之后它仍然会使用默认操作。如果您返回“true”,则表明您是一个快乐的编码员,并且需要完成的所有操作都已在您的 mySubroutine() 中发生,并且默认操作不需要执行操作。
Why not:
Just return false after you handle your code. This can be interpreted as no matter what your code (mySubroutine()) does it will still use the default action afterwards. If you return "true" you are telling that you are a happy coder and everything that needed to be done has happen in your mySubroutine() and the default action do not need to take action.
您可以通过执行以下操作来关闭键盘:
You can close the keyboard by doing:
您必须将 onClickListener 附加到执行以下代码的按钮:
You must attach an onClickListener to the button that executes the following code:
我也有同样的问题。在 editText VISIBILITY 从 GONE 更改为 VISIBLE 后,我必须立即设置焦点并显示软键盘。我使用以下代码实现了这一点:
I had the same problem. Immediately after editText VISIBILITY change from GONE to VISIBLE, I had to set the focus and display the soft keyboard. I achieved this using the following code: