本文介绍了座后退按钮在安卓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从回到其他活动阻止硬件后退按钮在Android中,以prevent .. 在此先感谢...
I want to block hardware back button in android ,in order to prevent from going back to other activity.. Thanks in advance...
推荐答案
下面是code,可让您正确处理活动的返回键上的所有平台版本:
Here is code that allows you to handle the back key in an activity correctly on all versions of the platform:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ( Integer.valueOf(android.os.Build.VERSION.SDK) < 7 //Instead use android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR
&& keyCode == KeyEvent.KEYCODE_BACK
&& event.getRepeatCount() == 0) {
// Take care of calling this method on earlier versions of
// the platform where it doesn't exist.
onBackPressed();
}
return super.onKeyDown(keyCode, event);
}
@Override
public void onBackPressed() {
// This will be called either automatically for you on 2.0
// or later, or by the code above on earlier versions of the
// platform.
return;
}
sources:http://android-developers.blogspot.com/2009/12/back-and-other-hard-keys-three-stories.html
sources:http://android-developers.blogspot.com/2009/12/back-and-other-hard-keys-three-stories.html
这篇关于座后退按钮在安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!