Android自定义从子级转换为父级Activity

时间:2016-06-02 12:15:36

标签: android android-activity back-button android-navigation

我有2 ActivitiesActivityAparent Activity的{​​{1}}:

我的ActivityB文件:

Manifest

我已将<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()时调用,而不是在&#34;返回箭头&#34; (按下屏幕的左上角)。

当按下Button时,我也想要自定义transition

enter image description here

有什么想法吗?

1 个答案:

答案 0 :(得分:3)

你可以通过以下方式完成:

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