WindowAnimationStyle

Posted 怪兽N

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WindowAnimationStyle相关的知识,希望对你有一定的参考价值。

WindowAnimationStyle

主题中定义窗口window或Activity的进入退出动画集合,用于theme的Style,例如/res/styles.xml下

    <!-- Base application theme. -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="android:textAllCaps">false</item>
        <item name="android:windowActionBar">false</item>
        <item name="windowActionBar">false</item>
        <item name="android:windowAnimationStyle">@style/AnimationActivity</item>
        <item name="windowNoTitle">true</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
    </style>

而自定义AnimationActivity如下

    <style name="AnimationActivity" parent="@android:style/Animation.Activity">
        <item name="android:activityOpenEnterAnimation">@anim/slide_in_left</item>
        <item name="android:activityOpenExitAnimation">@anim/slide_out_left</item>
        <item name="android:activityCloseEnterAnimation">@anim/slide_in_right</item>
        <item name="android:activityCloseExitAnimation">@anim/slide_out_right</item>
    </style>

其中@android:style/Animation.Activity为系统的style定义,如下

<!-- Window animation class attributes. -->
<declare-styleable name="WindowAnimation">
    <!-- The animation used when a window is being added. -->
    <attr name="windowEnterAnimation" format="reference" />
    <!-- The animation used when a window is being removed. -->
    <attr name="windowExitAnimation" format="reference" />
    <!-- The animation used when a window is going from INVISIBLE to VISIBLE. -->
    <attr name="windowShowAnimation" format="reference" />
    <!-- The animation used when a window is going from VISIBLE to INVISIBLE. -->
    <attr name="windowHideAnimation" format="reference" />

    <!--  When opening a new activity, this is the animation that is
          run on the next activity (which is entering the screen). -->
    <attr name="activityOpenEnterAnimation" format="reference" />
    <!--  When opening a new activity, this is the animation that is
          run on the previous activity (which is exiting the screen). -->
    <attr name="activityOpenExitAnimation" format="reference" />
    <!--  When closing the current activity, this is the animation that is
          run on the next activity (which is entering the screen). -->
    <attr name="activityCloseEnterAnimation" format="reference" />
    <!--  When closing the current activity, this is the animation that is
          run on the current activity (which is exiting the screen). -->
    <attr name="activityCloseExitAnimation" format="reference" />
    <!--  When opening an activity in a new task, this is the animation that is
          run on the activity of the new task (which is entering the screen). -->
    <attr name="taskOpenEnterAnimation" format="reference" />
    <!--  When opening an activity in a new task, this is the animation that is
          run on the activity of the old task (which is exiting the screen). -->
    <attr name="taskOpenExitAnimation" format="reference" />
    <!--  When opening an activity in a new task using Intent/FLAG_ACTIVITY_LAUNCH_BEHIND,
          this is the animation that is run on the activity of the new task (which is
          entering the screen and then leaving). -->
    <attr name="launchTaskBehindTargetAnimation" format="reference" />
    <!--  When opening an activity in a new task using Intent.FLAG_ACTIVITY_LAUNCH_BEHIND,
          this is the animation that is run on the activity of the old task (which is
          already on the screen and then stays on). -->
    <attr name="launchTaskBehindSourceAnimation" format="reference" />
    <!--  When closing the last activity of a task, this is the animation that is
          run on the activity of the next task (which is entering the screen). -->
    <attr name="taskCloseEnterAnimation" format="reference" />
    <!--  When opening an activity in a new task, this is the animation that is
          run on the activity of the old task (which is exiting the screen). -->
    <attr name="taskCloseExitAnimation" format="reference" />
    <!--  When bringing an existing task to the foreground, this is the
          animation that is run on the top activity of the task being brought
          to the foreground (which is entering the screen). -->
    <attr name="taskToFrontEnterAnimation" format="reference" />
    <!--  When bringing an existing task to the foreground, this is the
          animation that is run on the current foreground activity
          (which is exiting the screen). -->
    <attr name="taskToFrontExitAnimation" format="reference" />
    <!--  When sending the current task to the background, this is the
          animation that is run on the top activity of the task behind
          it (which is entering the screen). -->
    <attr name="taskToBackEnterAnimation" format="reference" />
    <!--  When sending the current task to the background, this is the
          animation that is run on the top activity of the current task
          (which is exiting the screen). -->
    <attr name="taskToBackExitAnimation" format="reference" />

    <!--  When opening a new activity that shows the wallpaper, while
          currently not showing the wallpaper, this is the animation that
          is run on the new wallpaper activity (which is entering the screen). -->
    <attr name="wallpaperOpenEnterAnimation" format="reference" />
    <!--  When opening a new activity that shows the wallpaper, while
          currently not showing the wallpaper, this is the animation that
          is run on the current activity (which is exiting the screen). -->
    <attr name="wallpaperOpenExitAnimation" format="reference" />
    <!--  When opening a new activity that hides the wallpaper, while
          currently showing the wallpaper, this is the animation that
          is run on the new activity (which is entering the screen). -->
    <attr name="wallpaperCloseEnterAnimation" format="reference" />
    <!--  When opening a new activity that hides the wallpaper, while
          currently showing the wallpaper, this is the animation that
          is run on the old wallpaper activity (which is exiting the screen). -->
    <attr name="wallpaperCloseExitAnimation" format="reference" />

    <!--  When opening a new activity that is on top of the wallpaper
          when the current activity is also on top of the wallpaper,
          this is the animation that is run on the new activity
          (which is entering the screen).  The wallpaper remains
          static behind the animation. -->
    <attr name="wallpaperIntraOpenEnterAnimation" format="reference" />
    <!--  When opening a new activity that is on top of the wallpaper
          when the current activity is also on top of the wallpaper,
          this is the animation that is run on the current activity
          (which is exiting the screen).  The wallpaper remains
          static behind the animation. -->
    <attr name="wallpaperIntraOpenExitAnimation" format="reference" />
    <!--  When closing a foreround activity that is on top of the wallpaper
          when the previous activity is also on top of the wallpaper,
          this is the animation that is run on the previous activity
          (which is entering the screen).  The wallpaper remains
          static behind the animation. -->
    <attr name="wallpaperIntraCloseEnterAnimation" format="reference" />
    <!--  When closing a foreround activity that is on top of the wallpaper
          when the previous activity is also on top of the wallpaper,
          this is the animation that is run on the current activity
          (which is exiting the screen).  The wallpaper remains
          static behind the animation. -->
    <attr name="wallpaperIntraCloseExitAnimation" format="reference" />

    <!--  When opening a new activity from a RemoteViews, this is the
          animation that is run on the next activity (which is entering the
          screen). Requires config_overrideRemoteViewsActivityTransition to
          be true. -->
    <attr name="activityOpenRemoteViewsEnterAnimation" format="reference" />

</declare-styleable>

可以还有定义系统的FragmentAnimation

    <!-- Fragment animation class attributes. -->
    <declare-styleable name="FragmentAnimation">
        <attr name="fragmentOpenEnterAnimation" format="reference" />
        <attr name="fragmentOpenExitAnimation" format="reference" />
        <attr name="fragmentCloseEnterAnimation" format="reference" />
        <attr name="fragmentCloseExitAnimation" format="reference" />
        <attr name="fragmentFadeEnterAnimation" format="reference" />
        <attr name="fragmentFadeExitAnimation" format="reference" />
    </declare-styleable>

以上是关于WindowAnimationStyle的主要内容,如果未能解决你的问题,请参考以下文章

windowAnimationStyle的动画无效

windowAnimationStyle的动画无效

windowAnimationStyle的动画无效

windowAnimationStyle的动画无效

windowAnimationStyle的动画无效

window的设置属性