简体   繁体   English

ActionBar向上按钮过渡效果

[英]ActionBar up button transition effect

I have already created a method for an animation when changing activities when the back button is pressed. 我已经在按下后退按钮时更改活动时创建了动画方法。 The problem is that the actionbar up button has the default transition effect to the previous activity and I can't find a way to override that animation and use a new one. 问题是操作栏向上按钮具有对前一个活动的默认过渡效果,我找不到覆盖该动画并使用新动画的方法。 Any ideas? 有任何想法吗? Thanks in advance 提前致谢

Preferably this would be hardcoded in java 优选地,这将在java中硬编码

Just get the event "home back" 刚举办活动“回家”

@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 ) 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 ) 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM