Android ActivityGroup 内后退按钮的使用
我正在使用 TabHost 开发一个应用程序。我正在使用 android 默认后退按钮通过覆盖每个选项卡的 ActivityGroup 内的 onBackPressed() 方法从当前活动返回到上一个活动。
现在,问题是,在我的一项活动中,我有一个 EditText,它在活动开始时获得焦点。然后,如果我按返回,它不会转到上一个活动,而是关闭应用程序。通过在互联网上搜索问题,我发现当 EditText 获得焦点(它是活动视图的子视图)时,活动会失去焦点,然后如果按下后退按钮,由于缺乏对当前活动的关注,它会关闭应用。我仍然有点困惑或者可以说不清楚这个问题。
因此,无论如何,我已经设法使用代码在运行时设置和删除对 EditText 的焦点。但现在,由于 EditText 没有焦点,如果按下后退按钮,则会关闭应用程序。我真的很困惑到底发生了什么。因此,如果有人对这个问题有任何想法或解决方案,请帮助解决这个问题。我将非常感激。谢谢。
I am developing an application using TabHost. I am using android default back button to move back to previous activity from current activity by overriding onBackPressed() method inside ActivityGroup of each tab.
Now , the problem is , in one of my activity i have an EditText which get focused when the activity starts. Then , if i press back , it does not go to previous activity , instead it closes the application. By searching about the problem on internet what i have found is that when the EditText get focused which is a child view of activity's view , the activity loss focus and then if back button is pressed , for lack of focus on the current activity it closes the application. Still i am little bit confused or can be say not clear about the problem.
So, any how , i have managed to set and remove focus over EditText on run time using code. But still now , as the EditText does not have focus , if the back button is pressed , it closes the application. I am really confused what's actually going on. So , if anyone have any idea or solution about the problem , please help on the issue. I will appreciate that very much. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过将 Key Listener 添加到 EditText 来覆盖此行为。试试这个,
You can override this behavior by adding Key Listener to your EditText. Try this out,
试试这个..
try this..
试试这个
try this