Android transition animation is not working

14,122

Solution 1

In my own case, for some reason, Transition Animation was off in the developer options of my android device.

Just go to Settings -> Developer Options -> Transition animation scale: set to Animation scale 1x

Solution 2

I found out that I need to really do

ActivityOptionsCompat activityOptionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, test, "transition_name");
ActivityCompat.startActivity(TourAndLoginActivity.this, new Intent(TourAndLoginActivity.this, LoginActivity.class), activityOptionsCompat.toBundle());

Still puzzling, but I don't know why we need to have a shared object to get the enter / exit transition. If I supply null instead of the ActivityOptionsCompat, there is no transition

Solution 3

Don't forget to apply the theme for the activity or the whole package in your AndroidManifest.xml.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android.package"
android:theme="@style/BaseAppTheme">
    ....
    ....
</manifest>
Share:
14,122
jason
Author by

jason

Updated on July 21, 2022

Comments

  • jason
    jason almost 2 years

    Android transition is same for explode and slide.Actually I don't think its animating. Also duration is not 6 seconds. How can I fix it?

    Code taken from here.

    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
    
            Transition ts = new Slide();  //Slide(); //Explode();
    
            ts.setDuration(6000);
            getWindow().setEnterTransition( ts );
            getWindow().setExitTransition( ts );
            setContentView(R.layout.activity_main_activity);
    
    
    
        }
    
    
    
    
        @Override
        public void onBackPressed() {
            super.onBackPressed();
            finishAfterTransition();
        }
    

    Style-v21.xml

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <style name="BaseAppTheme" parent="android:Theme.Material.Light">
            <item name="android:colorControlHighlight">#0000AA</item>
            <item name="android:navigationBarColor">#0000AA</item>
            <item name="android:colorPrimaryDark">#0000AA</item>
            <item name="android:colorPrimary">#0000FF</item>
            <item name="android:colorAccent">#00FF00</item>
            <item name="android:windowBackground">@android:color/black</item>
            <item name="android:textColorPrimary">@android:color/white</item>
    
            <item name="android:windowContentTransitions">true</item>
            <item name="android:windowAllowEnterTransitionOverlap">true</item>
    
            <!-- specify enter and exit transitions -->
            <item name="android:windowEnterTransition">@transition/explode</item>
            <item name="android:windowExitTransition">@transition/explode</item>
        </style>
    </resources>