Android implements a custom return button animation effect method _android

Source: Internet
Author: User

Today we'll talk about how to customize the animation effect of the return button in Andorid. I'll explain how to use it with a practical application.

First look at an effect screenshot, there is a search button at the top of a page:

I realized before the way is the same as Baidu/google home search results, similar to the AJAX request in Web development, the results are directly displayed on the current page (Drop-down effect). After referring to a number of apps later found that are entering a new page, so I will change to try. That's a lot of crap.

Then we clicked the Search box, will enter a new activity, here the animation effect is very simple, direct use overridependingtransition method can produce effect.

@Override public
void OnClick (View v) {
    Intent Intent = new Intent (activity, 
        Merchantssearchactivity.class );
    StartActivity (intent);
    Overridependingtransition (R.anim.in_from_right, 
        r.anim.out_to_left);
}

Go to the real search interface:

Here we have a return button, how to click the Back button, so that the page returned to the previous page and the animation effect is to slide right?

The first thought is rewriting

@Override public
void onbackpressed () {
 overridependingtransition (r.anim.in_from_left,
        r.anim.out_to_ right);
    Super.onbackpressed ();
}

It's no good trying this way.

Then, in the direction of the activity lifecycle, it is possible to add the animation effect code to the OnPause method:

protected void OnPause () {
    super.onpause ();
    Overridependingtransition (R.anim.in_from_left,
        r.anim.out_to_right);
}

Run, click Back. Perfectly run.

More interested readers of Android-related content can view this site: "Android Development Animation Tips", "Android Development introduction and Advanced Course" and "Android Control usage summary."

I hope this article will help you with the Android program.

Related Article

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.