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.
Related articles
- Customization of Item Click Effect in Android ListView
- Custom BaseTemplate for Android Rapid Development
- Android customize your own EditText to easily change the bottom line color
- Detailed Android component style customization method
- Android implementation of customized desktop method
- Method for customizing android shutdown interface of android source code exploration
- Android status bar customization and modification methods
- Detailed customization of android system