Android to set activity entry and exit effects

Source: Internet
Author: User

Looking at the source and resource files of Android, finally understand how to modify settings dialog and activity entry and exit effects. Setting dialog first obtains its window through the GetWindow () method, and then obtains the Windowmanager.layoutparams LP of Window through the GetAttributes () method, LP has a public property windowanimations, so long as the ID of the animation to be implemented is assigned to it. The question is how the animation should be written, and the study found that the effects of window entry and exit were set by @android: Windowenteranimation and @android:windowexitanimation two item, For example, when entering the Anim is @anim/dialog_enter, exit is @anim/dialog_exit, then declare a style:

<style name="mydialog">    <item name="@android: Windowenteranimation"> @anim/dialog_enter</item>    <item name="@android : Windowexitanimation"> @anim/dialog_exit</item></style>

Then pass the ID of this style to lp.windowanimations on the line.

Activity entry and exit effects can be achieved by @android: Activityopenenteranimation, @android: Activityopenexitanimation, @android: Activitycloseenteranimation, @android: activitycloseexitanimation These item settings, the first represents a new activity to create an entry effect, The 2nd indicates that the activity has not finished () the exit effect, the 3rd indicates that the previous activity returned the entry effect, and the 4th represents the activity finish () Exit effect ... (It seems a bit messy). The specific settings refer to the following:

<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>

And then the MyTheme this style as the activity of the theme on the line, there is another way is to get its window through acitvity, and then set the same settings as dialog, Because the windowanimations value in the layoutparams of the window is set in the final analysis. So the activity's entry and exit effects can also be @android:windowenteranimation and @android: windowexitanimation these two item settings.

Android to set activity entry and exit effects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.