Home>

Today we will talk about how to customize the animation of the back button in andorid.I will explain how to use it in combination with practical applications.

The way I implemented before is the same as the Baidu/google homepage search.Similar to ajax requests in web development, the results are displayed directly on the current page (drop down effect). Later, after referring to many apps, I found that they entered a new page.So I tried to change it.. Nonsense too much..

After we clicked on the search box,Will enter a new activity, the animation effect here is very simple,Use the overridependingtransition method directly to produce the 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);
}

Enter the real search interface:

Here we have a back button,How about clicking the back button,Return the page to the previous page and the animation effect slides to the right?

The first thought was to rewrite

@override
public void onbackpressed () {
 overridependingtransition (r.anim.in_from_left,        r.anim.out_to_right);
    super.onbackpressed ();
}

Try it like this,No way.

Then consider the direction of the activity life cycle,The feasible method is to add 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. Works perfectly.

  • Previous 21 days to learn Android development tutorial of SurfaceView and multi-threaded mashup
  • Next Android programming rewrites ViewGroup to implement card layout method
  • Trends