Aracılığıyla paylaş


Activity.OverrideActivityTransition Method

Definition

Overloads

OverrideActivityTransition(OverrideTransition, Int32, Int32)

Customizes the animation for the activity transition with this activity.

OverrideActivityTransition(OverrideTransition, Int32, Int32, Int32)

Customizes the animation for the activity transition with this activity.

OverrideActivityTransition(OverrideTransition, Int32, Int32)

Customizes the animation for the activity transition with this activity.

[Android.Runtime.Register("overrideActivityTransition", "(III)V", "GetOverrideActivityTransition_IIIHandler", ApiSince=34)]
public virtual void OverrideActivityTransition (Android.App.OverrideTransition overrideType, int enterAnim, int exitAnim);
[<Android.Runtime.Register("overrideActivityTransition", "(III)V", "GetOverrideActivityTransition_IIIHandler", ApiSince=34)>]
abstract member OverrideActivityTransition : Android.App.OverrideTransition * int * int -> unit
override this.OverrideActivityTransition : Android.App.OverrideTransition * int * int -> unit

Parameters

overrideType
OverrideTransition

OVERRIDE_TRANSITION_OPEN This animation will be used when starting/entering an activity. OVERRIDE_TRANSITION_CLOSE This animation will be used when finishing/closing an activity.

enterAnim
Int32

A resource ID of the animation resource to use for the incoming activity. Use 0 for no animation.

exitAnim
Int32

A resource ID of the animation resource to use for the outgoing activity. Use 0 for no animation.

Attributes

Remarks

Customizes the animation for the activity transition with this activity. This can be called at any time while the activity still alive.

This is a more robust method of overriding the transition animation at runtime without relying on #overridePendingTransition(int, int) which doesn't work for predictive back. However, the animation set from #overridePendingTransition(int, int) still has higher priority when the system is looking for the next transition animation.

The animations resources set by this method will be chosen if and only if the activity is on top of the task while activity transitions are being played. For example, if we want to customize the opening transition when launching Activity B which gets started from Activity A, we should call this method inside B's onCreate with overrideType = OVERRIDE_TRANSITION_OPEN because the Activity B will on top of the task. And if we want to customize the closing transition when finishing Activity B and back to Activity A, since B is still is above A, we should call this method in Activity B with overrideType = OVERRIDE_TRANSITION_CLOSE.

If an Activity has called this method, and it also set another activity animation by Window#setWindowAnimations(int), the system will choose the animation set from this method.

Note that Window#setWindowAnimations, #overridePendingTransition(int, int) and this method will be ignored if the Activity is started with ActivityOptions#makeSceneTransitionAnimation(Activity, Pair[]). Also note that this method can only be used to customize cross-activity transitions but not cross-task transitions which are fully non-customizable as of Android 11.

Java documentation for android.app.Activity.overrideActivityTransition(int, int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

OverrideActivityTransition(OverrideTransition, Int32, Int32, Int32)

Customizes the animation for the activity transition with this activity.

[Android.Runtime.Register("overrideActivityTransition", "(IIII)V", "GetOverrideActivityTransition_IIIIHandler", ApiSince=34)]
public virtual void OverrideActivityTransition (Android.App.OverrideTransition overrideType, int enterAnim, int exitAnim, int backgroundColor);
[<Android.Runtime.Register("overrideActivityTransition", "(IIII)V", "GetOverrideActivityTransition_IIIIHandler", ApiSince=34)>]
abstract member OverrideActivityTransition : Android.App.OverrideTransition * int * int * int -> unit
override this.OverrideActivityTransition : Android.App.OverrideTransition * int * int * int -> unit

Parameters

overrideType
OverrideTransition

OVERRIDE_TRANSITION_OPEN This animation will be used when starting/entering an activity. OVERRIDE_TRANSITION_CLOSE This animation will be used when finishing/closing an activity.

enterAnim
Int32

A resource ID of the animation resource to use for the incoming activity. Use 0 for no animation.

exitAnim
Int32

A resource ID of the animation resource to use for the outgoing activity. Use 0 for no animation.

backgroundColor
Int32

The background color to use for the background during the animation if the animation requires a background. Set to Color#TRANSPARENT to not override the default color.

Attributes

Remarks

Customizes the animation for the activity transition with this activity. This can be called at any time while the activity still alive.

This is a more robust method of overriding the transition animation at runtime without relying on #overridePendingTransition(int, int) which doesn't work for predictive back. However, the animation set from #overridePendingTransition(int, int) still has higher priority when the system is looking for the next transition animation.

The animations resources set by this method will be chosen if and only if the activity is on top of the task while activity transitions are being played. For example, if we want to customize the opening transition when launching Activity B which gets started from Activity A, we should call this method inside B's onCreate with overrideType = OVERRIDE_TRANSITION_OPEN because the Activity B will on top of the task. And if we want to customize the closing transition when finishing Activity B and back to Activity A, since B is still is above A, we should call this method in Activity B with overrideType = OVERRIDE_TRANSITION_CLOSE.

If an Activity has called this method, and it also set another activity animation by Window#setWindowAnimations(int), the system will choose the animation set from this method.

Note that Window#setWindowAnimations, #overridePendingTransition(int, int) and this method will be ignored if the Activity is started with ActivityOptions#makeSceneTransitionAnimation(Activity, Pair[]). Also note that this method can only be used to customize cross-activity transitions but not cross-task transitions which are fully non-customizable as of Android 11.

Java documentation for android.app.Activity.overrideActivityTransition(int, int, int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to