0

由于我的应用程序设计的某些功能,我需要在事件中开始新的活动onBackPressed

@Override
public void onBackPressed() {
    Intent intent = new Intent(this, SomeActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
}

问题是它看起来像用户在应用程序的深处进行 - 而不是用户返回。

因此,仅针对这种情况,我需要切换动画。我知道overridePendingTransition,但是如何获取系统默认动画(activityCloseEnterAnimation和其他动画)?

4

1 回答 1

1
@Override
public void onBackPressed() {
    TypedArray activityStyle = getTheme().obtainStyledAttributes(new int[] {android.R.attr.windowAnimationStyle});
    int windowAnimationStyleResId = activityStyle.getResourceId(0, 0);
    activityStyle.recycle();

    activityStyle = getTheme().obtainStyledAttributes(windowAnimationStyleResId, new int[] {android.R.attr.activityCloseEnterAnimation, android.R.attr.activityCloseExitAnimation});
    int activityCloseEnterAnimation = activityStyle.getResourceId(0, 0);
    int activityCloseExitAnimation = activityStyle.getResourceId(1, 0);
    activityStyle.recycle();

    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);

    overridePendingTransition(activityCloseEnterAnimation, activityCloseExitAnimation);
}
于 2013-03-18T09:20:36.823 回答