Reputation: 720
I have been trying for some months to get an activity transition to work. I have tried a number of approaches, using XML and styles, and code, to no avail. Below is my most recent attempt. Does anyone know why I can't get any transitions to appear?
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addSlideTransitions();
setContentView(R.layout.my_activity_layout);
....
}
protected void addSlideTransitions()
{
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
Slide slide = new Slide();
slide.setDuration(1000);
getWindow().setEnterTransition(slide);
getWindow().setExitTransition(slide);
}
Upvotes: 1
Views: 598
Reputation: 20926
You must start the activity with an ActivityOptions bundle created with makeSceneTransitionAnimation.
That type of transition also only works when in the same task (as of N).
Upvotes: 1
Reputation: 7533
Try adding the call to addSlideTransitions
before super.onCreate
.
@Override
protected void onCreate(Bundle savedInstanceState)
{
addSlideTransitions();
super.onCreate(savedInstanceState);
setContentView(R.layout.my_activity_layout);
....
}
Upvotes: 0
Reputation: 686
Try to do like this,I am sure this will work for you.
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addSlideTransitions();
setContentView(R.layout.activity_main);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected void addSlideTransitions()
{
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
Slide slide = new Slide();
slide.setDuration(1000);
getWindow().setEnterTransition(slide);
getWindow().setExitTransition(slide);
}
}
Upvotes: 0