[英]Android custom transition from child to parent Activity
I have 2 Activities
. 我有2个
Activities
。 ActivityA
is the parent Activity
of ActivityB
: ActivityA
是ActivityA
的parent Activity
ActivityB
:
My Manifest
file: 我的
Manifest
文件:
<activity
android:name=".ActivityA"
android:launchMode="singleTop" />
<activity
android:name=".ActivityB"
android:parentActivityName=".ActivityA"/>
I've changed the transition from ActivityA
to ActivityB
: 我已经改变了从
ActivityA
到ActivityB
的过渡:
final Intent intent = new Intent(this, ActivityB.class);
startActivity(intent);
overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
That works fine. 这很好。 But now I also want to change the transition when going back from
ActivityB
to ActivityA
. 但现在我也想从回去的时候改变过渡
ActivityB
到ActivityA
。 In my ActivityB
I override the method finish()
like this: 在我的
ActivityB
我重写方法finish()
如下所示:
@Override
public void finish() {
super.finish();
overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
}
The problem is that the finish()
method is only called when the hardware back Button
is pressed, but not when the "go back arrow" (top left corner of the screen) is pressed. 问题是
finish()
方法仅在按下硬件后退Button
时调用,而不是在按下“返回箭头”(屏幕左上角)时调用。
I also want the custom transition
when that Button
is pressed. 按下
Button
时,我也想要自定义transition
。
Any ideas? 有任何想法吗?
you can do it by: 你可以通过以下方式完成:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
}
return super.onOptionsItemSelected(item);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.