Start Activity with an animation

后端 未结 1 1899
太阳男子
太阳男子 2020-11-28 01:37

I am trying to start an activity with a custom transition animation. The only way I have found out so far to do this (without using onPendingTransition() in the previous act

相关标签:
1条回答
  • 2020-11-28 02:10

    I am using this in a current project of mine, it is basically pretty simple. You define a new animation style in your styles.xml, like this:

    <!-- just defines top layer "Animation" -->
    <style name="Animation" />
    
    <!-- the animations must have been defined in your "anim" folder, of course -->
    <style name="Animation.MyAwesomeAnimation" parent="android:style/Animation.Activity">
        <item name="android:activityOpenEnterAnimation">@anim/myawesomeanimation_enter</item>
        <item name="android:activityOpenExitAnimation">@anim/hold_long</item>
        <item name="android:activityCloseEnterAnimation">@anim/hold_long</item>
        <item name="android:activityCloseExitAnimation">@anim/myawesomeanimation_exit</item>
    </style>
    

    Then set this style in a theme (themes.xml):

    <style name="Theme.MyAwesomeTheme" parent="Theme.Default">
        <item name="android:windowAnimationStyle">@style/Animation.MyAwesomeAnimation</item>
    </style>
    

    And then you can simply set these themes to every activity you like in your AndroidManifest.xml:

    <activity
        android:name=".MyAwesomeActivity"
        android:theme="@style/Theme.MyAwesomeTheme" />
    

    Now I wish you big fun with activity animations! :-D

    0 讨论(0)
提交回复
热议问题