3

I have one android app in which the whole app theme is not Material theme so for the new activities i have made another Material theme. The material widgets like TextInputLayout and others are working fine but the material transitions are not working.

I have created an xml file in res>transitions>explode.xml and in that I have made this transition:

<?xml version="1.0" encoding="utf-8"?>
<explode xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="5000">

</explode>

and my material theme in style.xml is:

<style name="MaterialTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/logo_color</item>
        <item name="android:statusBarColor">@android:color/white</item>
        <item name="colorControlActivated">@color/name_primary_color</item>
        <item name="colorControlHighlight">#A3ABBC</item>
        <item name="android:navigationBarColor" tools:targetApi="lollipop">@color/name_primary_color</item>
        <item name="android:windowLightStatusBar" tools:targetApi="23">true</item>

        <item name="android:windowActivityTransitions">true</item>
        <!-- specify enter and exit transitions -->
        <item name="android:windowEnterTransition">@transition/explode</item>
        <item name="android:windowExitTransition">@transition/explode</item>
        <!-- specify shared element transitions -->
        <item name="android:windowSharedElementEnterTransition">
            @transition/change_image_transform</item>
        <item name="android:windowSharedElementExitTransition">
            @transition/change_image_transform</item>
    </style>

Now when I switch from one activity to another then the transition should work but it is not. I have also tried by defining transition in activities like:

private fun setupWindowAnimations() {
        val slide =
            TransitionInflater.from(this).inflateTransition(R.transition.explode)
        window.exitTransition = slide
    }

It is also not working so what should I am doing wrong here? Please help.

Cosmic Dev
  • 522
  • 6
  • 20

1 Answers1

0

Your MaterialTheme should inherit a Theme.Material.*, not Theme.MaterialComponents.*.

For example:

<style name="MaterialTheme" parent="android:Theme.Material.Light.NoActionBar">

If you cannot use a Theme.Material.* as a base theme, you can use the windowAnimationStyle to define the enter and exit animations instead of the Material transitions. See this answer for an example.

Nit
  • 1,115
  • 9
  • 9