2

I would like to change the animation between page transitions on Android by extending the NavigationPageRenderer. However, unlike the Xamarin.Forms.Platform.Android.NavigationRenderer, there aren't any methods for OnPopToRootAsync, OnPopViewAsync, and OnPushAsync. Is it possible to override the transition on a page with the AppCompat.NavigationPageRenderer?

2 Answers 2

3

You will need to add a custom renderer for the NavigationPageRenderer, and override the SetupPageTransition.

[assembly: ExportRenderer(typeof(NavigationPage), typeof(AnimationNavigationRenderer))]
namespace ProjectName.Droid
{
    public class AnimationNavigationRenderer : Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer
    {
        protected override void SetupPageTransition(Android.Support.V4.App.FragmentTransaction transaction, bool isPush)
        {
            if (isPush)
                transaction.SetCustomAnimations(Resource.Animation.abc_slide_in_top, 0, 0, Resource.Animation.abc_slide_out_top);
            else
                transaction.SetCustomAnimations(Resource.Animation.abc_slide_in_top, 0, 0, Resource.Animation.abc_slide_out_top);
        }
    }
}
1
  • For more information, check out the Xamarin.Forms/Xamarin.Forms.Platform.Android/AppCompat/NavigationPageRenderer.cs on GitHub (2.3.0 branch) github.com/xamarin
    – oddbear
    Jun 21, 2016 at 8:14
0

For Android X use it like this:

protected override void SetupPageTransition(AndroidX.Fragment.App.FragmentTransaction transaction, bool isPush)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.