100*_*abh 17
以下代码允许您在平台的所有版本上正确处理活动中的后退键:
@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;
}
Run Code Online (Sandbox Code Playgroud)
来源:HTTP://android-developers.blogspot.com/2009/12/back-and-other-hard-keys-three-stories.html
| 归档时间: |
|
| 查看次数: |
7451 次 |
| 最近记录: |