【问题标题】:Back shared element transition between activities活动之间的反向共享元素转换
【发布时间】:2017-10-09 16:29:16
【问题描述】:

我使用原生 Android 转换 API 为活动之间的转换设置动画。这是我用来启动活动的来源:

        Intent intent = new Intent(MainActivity.this, DetailActivity.class);
        Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(MainActivity.this, imageView, imageView.getTransitionName()).toBundle();

        MainActivity.this.startActivity(intent, bundle);

当我点击硬件后退按钮时,它会以预期的反向过渡动画返回上一个活动,但当我点击工具栏中的“向上”按钮时,它会以默认动画返回上一个活动:

【问题讨论】:

    标签: android animation android-animation android-transitions shared-element-transition


    【解决方案1】:

    将以下代码添加到正在完成的活动中:

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            // Respond to the action bar's Up/Home button
            case android.R.id.home:
                supportFinishAfterTransition();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }
    

    Source

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-30
      • 1970-01-01
      • 2016-11-18
      • 2015-04-07
      • 2015-10-26
      相关资源
      最近更新 更多