关于android:windowAnimationStyle

关于android:windowAnimationStyle

android:windowAnimationStyle分为两种,一种是activityAnimation,一种是windowAnimation。

一、ActivityAnimation

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    "android:windowAnimationStyle">@style/activityAnimation
style>

<style name="activityAnimation" parent="@android:style/Animation.Activity">
    "android:activityOpenEnterAnimation">@anim/slide_right_in
    "android:activityOpenExitAnimation">@anim/slide_left_out
    "android:activityCloseEnterAnimation">@anim/slide_left_in
    "android:activityCloseExitAnimation">@anim/slide_right_out
style>
  • 从A1启动A2:
    • android:activityOpenEnterAnimation:A2进入动画
    • android:activityOpenExitAnimation:A1退出动画
  • 从A2返回A1:
    • android:activityCloseEnterAnimation:A1进入动画
    • android:activityCloseExitAnimation:A2退出动画

二、WindowAnimationStyle

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    "android:windowAnimationStyle">@style/windowAnimation
style>

<style name="windowAnimation" parent="@android:style/Animation">
     "android:windowEnterAnimation">@anim/slide_left_enter
     "android:windowExitAnimation">@anim/slide_right_exit
 style>

只对当前启动的Activity生效,分别是进入和退出动画。一般用于Dialog或者透明Activity。
当Activity设置了android:windowIsTranslucent=true时,给Activity设置ActivityAnimation会不起作用,只能设置windowAnimation:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    "android:windowIsTranslucent">true
    "android:windowAnimationStyle">@style/windowAnimation
style>

<style name="windowAnimation" parent="@android:style/Animation.Translucent">
     "android:windowEnterAnimation">@anim/slide_left_enter
     "android:windowExitAnimation">@anim/slide_right_exit
 style>

你可能感兴趣的:(android)