Android - 活动和导航?
- 我从 Activity1 导航到 Activity2 在活动 2 中,我有一个键盘,并且在选择后退按钮并转到活动 1 后,该键盘保留在屏幕上。
这就是我解决此问题的方法
// This code is in Activity 2
@Override
public void onBackPressed() {
startActivity(intentForActivity1);
finish();
}
这是对我的问题的错误解决方案吗? 手动处理后退按钮是一个坏主意吗?
- I navigate from Activity1 to Activity2
On Activity 2 I have a keyboard and this keyboard stays on the screen after selecting the back button and going to Activity 1.
This is how I fixed this issue
// This code is in Activity 2
@Override
public void onBackPressed() {
startActivity(intentForActivity1);
finish();
}
Is this a wrong solution to my problem?
Is it a bad idea to handle the back button manually?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您正在捕获后退按钮按下操作,因此软键盘很可能不会接收到按下操作,因此它不会隐藏。
尝试自己隐藏它:
有关隐藏键盘的此方法的更多详细信息,请参阅 Reto Meier 的答案: 关闭/隐藏Android软键盘
Since you're capturing the back button press, most probably the soft keyboard does not receive the press and thus it does not hide.
Try hiding it yourself:
See Reto Meier's answer for more details on this method to hide the keyboard: Close/hide the Android Soft Keyboard
覆盖后退按钮本身并没有什么问题。只需确保该行为不会让用户感到困惑即可。
另外,如果您只是想隐藏软键盘(例如,您在选项卡或类似的东西之间切换),您可以使用 InputMethodManager。这是一个线程,人们在其中讨论了执行此操作的方法。
There's nothing inherently wrong with overriding the back button. Just make sure the behavior isn't confusing to the user.
Also, if you ever just want to hide the soft keyboard (say, you're switching between tabs or something like that), you can use InputMethodManager. Here's a thread where people discussed ways to do this.