我想在下一个活动中添加一个输入转换.
所以我做了:
getWindow().requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS); window.setEnterTransition(new Slide());
这似乎不起作用.在做了一些试验和错误之后(因为我将这个转换用于其他活动)我发现它在调用后确实有效
ActivityOptionsCompat activityOptionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(activity,view,"some_name"); ActivityCompat.startActivity(activity,new Intent(TourAndLoginActivity.this,LoginActivity.class),activityOptionsCompat.toBundle());
解决方法
取自Android开发者文档:
Start an activity using transitions
If you enable transitions and set an exit transition for an activity,the transition is activated when you launch another activity as follows:startActivity(intent,ActivityOptions.makeSceneTransitionAnimation(this).toBundle());If you have set an enter transition for the second activity,the transition is also activated when the activity starts. To disable transitions when you start another activity,provide a null options bundle.
https://developer.android.com/training/material/animations.html
因此,首先启用转换,如下所示:
getWindow().requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS); window.setEnterTransition(new Slide());然后开始活动如下:
startActivity(intent,ActivityOptions.makeSceneTransitionAnimation(this).toBundle());