Shared element transitions
In our example, we gave our activity a transparent background by using @android:style/
Theme.Translucent.NoTitleBar. This theme does not inherit from the Material theme, so it does not
have activity transitions turned on. They have to be turned on manually, which can happen in either of
two ways. One option is to add a line of code to the activity, like this:
Listing 35.6 Turning on activity transitions in code
@Override
public void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS);
super.onCreate(savedInstanceState);
...
}
The other way is to tweak the style the activity uses and set the android:windowActivityTransitions
attribute to true.
Listing 35.7 Turning on activity transitions in a style
parent="@android:style/Theme.Translucent.NoTitleBar">
The next step in the shared element transition is to tag each shared element view with a transition
name. This is done in a property on View introduced in API 21: transitionName. You can set it in
either XML or in code; depending on the circumstance, one or the other might be appropriate. In our
case, we set the transition name for the zoomed-in image by setting android:transitionName to
image in our layout XML, as in Figure 35.9.
Figure 35.9 Zoomed-in image layout