Android的 - 当默认后退按钮是pressed如何动画的活动转变按钮、动画、Android、pressed

由网友(漓奚)分享简介:在我的活动,我有以下点击监听器是伟大的工作的一个按钮:In my activity, I have a button with the following click listener that is working great:final ImageButton startOverButton = (ImageB...

在我的活动,我有以下点击监听器是伟大的工作的一个按钮:

In my activity, I have a button with the following click listener that is working great:

final ImageButton startOverButton = (ImageButton) findViewById(R.id.start_over_button);
startOverButton.setOnClickListener(new View.OnClickListener(){

    @Override
    public void onClick(final View v) {

        finish();//go back to the previous Activity
        overridePendingTransition(R.anim.comming_in, R.anim.comming_out);
    }
});

这动画的回归previous活动我想要的方式。然而,当用户presses Android的默认返回按钮,动画不会被触发。我的问题是:我应该在哪里把动画code的 overridePendingTransition(R.anim.comming_in,R.anim.comming_out); 的使这个动画将被触​​发既当用户点击我按钮,在默认的Andr​​oid后退按钮?

It animates the return to the previous activity the way I want. However, when the user presses the Android default back button, the animation is not triggered. My question is: where should I put the animation code overridePendingTransition(R.anim.comming_in, R.anim.comming_out); so that this animation will be triggered both when the user clicks on my button and in the default Android back button?

作为一个幼稚的尝试,我试图把的 overridePendingTransition(R.anim.comming_in,R.anim.comming_out); 的的code在行的的onDestroy() 的方法,但没有奏效。

As a naive try, I have tried to put the overridePendingTransition(R.anim.comming_in, R.anim.comming_out); line of code in the onDestroy() method but it did not work.

感谢你在前进!

推荐答案

也许你可以在活动做好这项工作的onBack pressed()方法。

maybe you can do this work in onBackPressed() method in the activity.

@Override
public void onBackPressed() {
    super.onBackPressed();
    overridePendingTransition(R.anim.comming_in, R.anim.comming_out);   
}
阅读全文

相关推荐

最新文章