截获后退按钮 [英] Intercepting the back button
本文介绍了截获后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在写这将有两个活动,当用户presses在第二个活动一个对话框会弹出要求用户确认操作后退按钮的应用程序。那么,如何拦截呢?我严重怀疑这个怎么把backstack是操作系统本身的一部分。有没有人找到了一个解决办法?
I'm writing an application which will have two Activities, when the user presses the back button on the second activity a dialog should pop up asking the user to confirm the action. So how do I intercept this? I seriously doubt about this coz the backstack is a part of the OS itself. Has anyone found a workaround?
推荐答案
在一个活动,你可以只覆盖
In an activity you can just override
onBack pressed()
onBackPressed()
编辑:这是API LVL 5+:/ 4和下面你得重写的onkeydown()
edit: that is api lvl 5+ :/ for 4 and below you gotta override onKeyDown()
这篇关于截获后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文