Why my close activity animation doesn't work on Android 4.0 (ICS)

微笑、不失礼 提交于 2019-12-01 06:32:18

Specifying animations from the manifest appears to be broken in ICS :-( The override animation solution works fine, but you probably don't want to hard-code the animations. It would be nice to get them from the manifest as you would for other versions of the platform.. so....

add a couple of member fields to your activity to hold the ids of the animations attached to your activity..

protected int activityCloseEnterAnimation;
protected int activityCloseExitAnimation;

and somewhere in your onCreate...

// Retrieve the animations set in the theme applied to this activity in the
// manifest..
TypedArray activityStyle = getTheme().obtainStyledAttributes(new int[] {android.R.attr.windowAnimationStyle});
int windowAnimationStyleResId = activityStyle.getResourceId(0, 0);      
activityStyle.recycle();

// Now retrieve the resource ids of the actual animations used in the animation style pointed to by 
// the window animation resource id.
activityStyle = getTheme().obtainStyledAttributes(windowAnimationStyleResId, new int[] {android.R.attr.activityCloseEnterAnimation, android.R.attr.activityCloseExitAnimation});
activityCloseEnterAnimation = activityStyle.getResourceId(0, 0);
activityCloseExitAnimation = activityStyle.getResourceId(1, 0);
activityStyle.recycle();

then wherever your activity finishes/should apply animation include...

overridePendingTransition(activityCloseEnterAnimation, activityCloseExitAnimation);

and your activities should correctly honour the animations you set in the theme/style attached to activities in your manifest.

I have also tried but its not working here. Don't know what is the problem but this.overridePendingTransition(R.anim.no_anim,R.anim.push_down_out_no_alpha); this code is working fine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!