当按下后退按钮时更改活动时,我已经创建了一个动画方法。问题是操作栏向上按钮具有到前一个活动的默认过渡效果,我找不到覆盖该动画并使用新动画的方法。有任何想法吗?提前致谢
最好这将在java中进行硬编码
只需获得“回家”活动
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
overridePendingTransition(R.animator.anim_left, R.animator.anim_right);
return true;
}
return false;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void onBackPressed() {
this.finish();
overridePendingTransition(R.anim.fade_in, R.anim.right_slide_out);
}
fade_in.xml ( R.anim.fade_in )
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromAlpha="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:toAlpha="1.0" />
right_slide_out.xml ( R.anim.right_slide_out )
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator">
<translate
android:duration="200"
android:fromXDelta="0"
android:toXDelta="100%p" />
</set>