Search code examples
androidandroid-fragmentsandroid-dialogfragmentmaterial-design

DialogFragment with custom windowAnimations; How do I add an AnimationListener to dialogfragment?


I want to animate in a new dialogfragment, and after the animation completes, I want to do another quick reveal animation to display the contents.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) 
{
    final Dialog dialog = super.onCreateDialog(savedInstanceState);
    dialog.getWindow().getAttributes().windowAnimations =     R.style.detailDialogAnimation;
    return dialog;
}

This is how I'm setting the window animations, however, I now need a way to determine when the animatinos in R.style.detailDialogAnimation have completed. Is there a callback I can receive from the fragment once these animations have completed?

I've tried overriding the onShow listener, but that seems to be called before the animations begin.


Solution

  • I couldn't find any information on getting a callback for window animations.

    I ended up setting a GlobalLayoutListener to my dialogs rootview and calling the animation from there.

    rootView.getViewTreeObserver().addOnGlobalLayoutListener(...);