title: Android shared element transition between an activity with a fragment to another activity with a fragment
body: <p>I have an ActivityA containing FragmentA and would like to make a shared element transition to ActivityB containing FragmentB. </p>
  
  <p>In the activities the shared element would be the toolbar. In the fragments it would be a textview. Is there anyway to do this? </p>
  
  <p>If not how could I make a shared element transition between both fragments in the activities?</p>
  
  <p>Thanks in advance for any help. I have been stuck a while. </p>
  
  <p>Okay so I will provide some code to clarify.</p>
  
  <p>Here I have MainActivity:</p>
  
  <pre><code>&lt;android.support.design.widget.CoordinatorLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:id="@+id/content"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:fitsSystemWindows="true"&gt;
  
      &lt;android.support.design.widget.AppBarLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:theme="@style/AppTheme.AppBarOverlay"&gt;
  
          &lt;!-- This is shared with DetailActivity --&gt;
          &lt;android.support.v7.widget.Toolbar
              android:id="@+id/toolbar"
              android:layout_width="match_parent"
              android:layout_height="?attr/actionBarSize"
              android:background="?attr/colorPrimary"
              app:popupTheme="@style/AppTheme.PopupOverlay"
              android:transitionName="sharedToolbar"/&gt;
  
      &lt;/android.support.design.widget.AppBarLayout&gt;
  
      &lt;!-- This contains MainFragment --&gt;
      &lt;FrameLayout
          android:id="@+id/activity_main_container"
          android:layout_width="match_parent"
          android:layout_height="match_parent"/&gt;
  
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p>This activity contains this fragment called MainFragment:</p>
  
  <pre><code>&lt;FrameLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
  
      &lt;!-- This element is shared with DetailFragment --&gt;
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:text="Fragment main"
          android:transitionName="sharedFragment"/&gt;
  
      &lt;!-- When this is clicked show next screen --&gt;
      &lt;Button
          android:id="@+id/fragment_main_button"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Go to detail screen"
          android:layout_gravity="bottom|center"/&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>Now what I want to do is when I click the button in MainFragment I want to perform a fragment transaction to this activity called the DetailActivity:</p>
  
  <pre><code>&lt;android.support.design.widget.CoordinatorLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:id="@+id/content"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:fitsSystemWindows="true"&gt;
  
      &lt;android.support.design.widget.AppBarLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:theme="@style/AppTheme.AppBarOverlay"&gt;
  
          &lt;!-- This is shared with MainActivity --&gt;
          &lt;android.support.v7.widget.Toolbar
              android:id="@+id/toolbar"
              android:layout_width="match_parent"
              android:layout_height="?attr/actionBarSize"
              android:background="?attr/colorPrimary"
              app:popupTheme="@style/AppTheme.PopupOverlay"
              android:transitionName="sharedToolbar"/&gt;
  
      &lt;/android.support.design.widget.AppBarLayout&gt;
  
      &lt;!-- This contains DetailFragment --&gt;
      &lt;FrameLayout
          android:id="@+id/activity_detail_container"
          android:layout_width="match_parent"
          android:layout_height="match_parent"/&gt;
  
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p>This activity contains this fragment called DetailFragment:</p>
  
  <pre><code>&lt;FrameLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
  
      &lt;!-- This element is shared with MainFragment --&gt;
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:text="Fragment detail"
          android:transitionName="sharedFragment"/&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>As you can see in the code both activities share the toolbar and has the same transition name. Their containing fragments both have a textview which I would like to animate in the transition as well. These textviews also has the same transition name. Is there anyway to do this? I have tried and so far I could only animate the toolbar between the two activities. How do I make the fragments perform a shared element transition at the same time? </p>
  
  <p>If this can't be done, how could I make it so when I navigate from MainActivity to DetailActivity that the textview of the fragments are what appears as the transition so not the toolbars(If I cant animate activity and fragment transactions at the same time).</p>