Android从子级到父级Activity的自定义过渡
作者:互联网
我有2个活动. ActivityA是ActivityB的父Activity:
我的清单文件:
<activity
android:name=".ActivityA"
android:launchMode="singleTop" />
<activity
android:name=".ActivityB"
android:parentActivityName=".ActivityA"/>
我已经从ActivityA更改为ActivityB:
final Intent intent = new Intent(this, ActivityB.class);
startActivity(intent);
overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
很好但是现在,我也想更改从ActivityB返回到ActivityA时的过渡.在我的ActivityB中,我像这样重写了finish()方法:
@Override
public void finish() {
super.finish();
overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
}
问题在于,仅当按下硬件后退按钮时才调用finish()方法,而在按下“后退箭头”(屏幕的左上角)时不调用finish()方法.
我也想要按下按钮时的自定义过渡.
有任何想法吗?
解决方法:
您可以通过以下方式做到:
@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);
}
标签:android-activity,back-button,android-navigation,android 来源: https://codeday.me/bug/20191118/2029231.html