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.