Search code examples
androidandroid-collapsingtoolbarlayoutandroid-transitionsshared-element-transition

Can I make a CollapsingToolbar that collapses on a transition instead of on scroll?


I currently have a collapsing toolbar in one activity. When pressing a button in a fragment in this activity, a new activity is opened that has a normal toolbar. The same TextView is the title in both toolbars, and I would like the transition of the toolbar to look just like it does in the normal use of CollapsingToolbarLayout. I have tried using a shared element transition between the two activities by using that TextView as the shared element, but it doesn't seem to be working.

So is it even possible to cause the "collapse" animation as a transition, or am I out of luck here?


Solution

  • You could try to collapse the toolbar like this:

    appBarLayout.setExpanded(false, true);
    

    That animates it. And then open your new Activity.