Android is set to enter and exit the effect Activity

  See the Android source code and resource files, finally understand how to modify the settings for Dialog and Activity entry and exit effects. Set the Dialog first through the getWindow () method to obtain its window, and then through the getAttributes () method to obtain the window WindowManager.LayoutParams LP, LP has a public property of the windowAnimations, as long as the realization of animation ID assigned to it. The problem is that animation should be how to write it, the study found, window to enter and exit through the @android:windowEnterAnimation and @android:windowExitAnimation were two item set, such as the anim @anim/dialog_enter, quit is @anim/ dialog_exit, a style statement:

<style name="mydialog">

<item name="@android:windowEnterAnimation">@anim/dialog_enter</item>

   <item name="@android:windowExitAnimation">@anim/dialog_exit</item>

</style>

Then the style ID to the lp.windowAnimations.

To enter and exit the effect of Activity through @android:activityOpenEnterAnimation, @android:activityOpenExitAnimation, @android:activityCloseEnterAnimation, @Android:activityCloseExitAnimation the item setting, The first said the new activity creation into effect, The second said activity is not finish (exit) effect, Third represents the last activity back into effect, The fourth representation is finish (activity) after the withdrawal effect... (a bit like a mess). The specific set.:

  <style name="myact">

<item name="@android:activityOpenEnterAnimation">@anim/act_enter</item>

<item name="@android:activityOpenExitAnimation">@anim/act_exit</item>

<item name="@android:activityCloseEnterAnimation">@anim/act_enter</item>

<item name="@android:activityCloseExitAnimation">@anim/act_exit</item>

  </style>

<style name="mytheme" parent="@android:style/Theme"> 

<item name="@android:windowAnimationStyle">@style/myact</item>

  </style>

Then the mytheme of this style as Activity theme on the line, there is a way to get it through the window Acitvity, and then set the dialog setting, because in the final analysis is to set up the Window layoutparams windowAnimations value. So the Activity entry and exit effects can also be achieved by @android:windowEnterAnimation and @android:windowExitAnimation two item set.

Posted by Harvey at November 15, 2013 - 10:51 PM