Following is my scenario.
I have an Activity
MainActivity
which has one FAB
. When the user clicks on FAB
, I open a full screen DialogFragment
. I want to open the DialogFragment
with some transitions.
Here is the code that I have tried so far.
//MainActivity.java
final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ReviewDialog reviewDialog = ReviewDialog.newInstance();
Slide slide = new Slide();
slide.setSlideEdge(Gravity.LEFT);
slide.setDuration(1000);
reviewDialog.setEnterTransition(slide);
Bundle bundle =ActivityOptions.makeSceneTransitionAnimation(ScrollingActivity.this)
.toBundle();
reviewDialog.setArguments(bundle);
reviewDialog.show(getSupportFragmentManager(),"review");
}
});
And here is the code of the DialogFragment ReviewDialog.
//ReviewDialog.java
public class ReviewDialog extends DialogFragment {
static ReviewDialog newInstance() {
ReviewDialog f = new ReviewDialog();
// Supply num input as an argument.
Bundle args = new Bundle();
f.setArguments(args);
return f;
}
@Override
public void onActivityCreated(Bundle arg0) {
super.onActivityCreated(arg0);
Slide slide = new Slide();
slide.setSlideEdge(Gravity.LEFT);
slide.setDuration(1000);
getDialog().getWindow().setEnterTransition(slide);
getDialog().getWindow().setExitTransition(slide);
getDialog().getWindow().setReenterTransition(slide);}
@Override
public void onCreate(Bundle bundle){
super.onCreate(bundle);
setStyle(DialogFragment.STYLE_NORMAL,R.style.DialogTheme);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.dialog_review, container, false);
return v;
}
}
Also I have set the following property in my AndroidManifest.xml
<item name="android:windowContentTransitions">true</item>
The problem is when the ReviewDialog is started, it doesn't show any transitions. I am able to show transitions between different activities but finding it very hard to show transition between Activity and Fragment. How to show transitions when a DialogFragment is started ?