To solve this I'd recommend looking into android.support.v4.app.ActivityOptionsCompat.makeSceneTransitionAnimation()
.
Here are the snippets from the code I remember:
I have ActivityA
which contains an EditTextA
.
The EditTextA
has a View.OnClickListener
:
View.OnClickListener() {
@Override
public void onClick(View view) {
ActivityB.launch(getActivity(), view);
}
}
which when invoked calls a static method: ActivityB.launch(Activity a, View transitionView)
:
public static void launch(Activity activity, View transitionView) {
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(
activity, transitionView, EXTRA_TRANSITION_VIEW);
Intent intent = new Intent(activity, ActivityB.class);
ActivityCompat.startActivity(activity, intent, options.toBundle());
}
The code above is basically creating an Intent
that will launch ActivityB. That Intent
also includes a Bundle
(options.toBundle()
) which has a bunch of stuff, including the view that is transitioning from ActivityA
to ActivityB
. In my case this is the EditTextA
.
In ActivityB.onCreate()
all we need to do is "connect" that view to the new view it's transitioning to. So in my case, EditTextA
is transitioning to another EditTextB
that lives in ActivityB
.
ActivityB.onCreate() {
....
mEditTextB = (EditText) findByViewId(...);
ViewCompat.setTransitionName(mEditTextB, EXTRA_TRANSITION_VIEW);
}
If I remember everything correctly that should be it :).