Android style exit animation resolves exiting animation invalid issue

Source: Internet
Author: User

    • In the activity statement inside the Androidmenifest.xml file, add your own theme statement, as follows:

<activity

Android:name= ". Myorderlistserviceactivity "

Android:theme= "@style/mytheme"

>

    • In the Style.xml file of the values of the declaration of a style, named MyTheme, notice that there is something I customize, related to the declaration of animation, only <item name= "Android:windowanimationstyle" > @style/animationactivity</item> this one.

<style name= "MyTheme" >

<!--Float_box for us to define the window background--

<item name= "android:backgrounddimenabled" >true</item>

<item name= "Android:windowframe" > @null </item>

<item name= "Android:windowbackground" > @android:color/transparent</item>

<item name= "Android:windowistranslucent" >true</item>

<item name= "Android:windowcontentoverlay" > @null </item>

<item name= "Android:windownotitle" >true</item>

<item name= "Android:windowfullscreen" >true</item>

<item name= "Android:windowanimationstyle" > @style/animationactivity</item>

</style>

  • In the Style.xml file of the values of the declaration of a style, named Animationactivity, yes is the above mytheme in the implementation of the Windowanimationstyle, as follows:

    <style name= "Animationactivity" mce_bogus= "1" parent= "@android: Style/animation.activity" >

    <item name= "Android:activityopenenteranimation" > @anim/slide_in_bottom</item>

    <item name= "Android:activityopenexitanimation" > @anim/slide_out_bottom</item>

    <item name= "Android:activitycloseenteranimation" > @anim/slide_in_bottom</item>

    <item name= "Android:activitycloseexitanimation" > @anim/slide_out_bottom</item>

    </style>

  • Add the above content, some machines although the animation is available, but the exit animation is not valid, but also need to add some code in your activity, to ensure the perfect operation of animation

  • Add Global variables

    protected int activitycloseenteranimation;

    protected int Activitycloseexitanimation

  • Add the following code to the OnCreate:

    TypedArray Activitystyle = Gettheme (). Obtainstyledattributes (New int[] {Android. R.attr.windowanimationstyle});

    int windowanimationstyleresid = Activitystyle.getresourceid (0, 0);

    Activitystyle.recycle ();

    Activitystyle = Gettheme (). Obtainstyledattributes (Windowanimationstyleresid, new int[] {Android. R.attr.activitycloseenteranimation, Android. R.attr.activitycloseexitanimation});

    activitycloseenteranimation = Activitystyle.getresourceid (0, 0);

    Activitycloseexitanimation = Activitystyle.getresourceid (1, 0);

    Activitystyle.recycle ();

  • Before you finish the program, you need to call the following code:

    Overridependingtransition (Activitycloseenteranimation, activitycloseexitanimation);

    The example I call is as follows:

    @Override

    public void Finish () {

    LOG.I (TAG, "Finish");

    Super.finish ();

    Overridependingtransition (Activitycloseenteranimation, activitycloseexitanimation);

    }

That's all you can do.

Android style exit animation resolves exiting animation invalid issue

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.