0

I just wanted to add an animation to my Dialog box when appearing and disappearing, there I found this thread:

Animate a custom Dialog

I did as it was described, here's my code:

 Dialog dialog = new Dialog(this, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.getWindow().getAttributes().windowAnimations = R.style.FinishDialog;
    dialog.setCancelable(true);   
    dialog.setCanceledOnTouchOutside(true);    
    dialog.setContentView(R.layout.dialog_next);
    dialog.show();

I chose android.R.style.Theme_Black_NoTitleBar_Fullscreen because I wanted to have a fullscreen dialog box which appears within an animation. This animation is called "R.style.FinishDialog" Here's the code for that:

<style name="FinishDialog" parent="@android:style/Theme.Dialog">
    <item name="android:windowAnimationStyle">@style/FinishDialogAnimation</item>
</style>

<style name="FinishDialogAnimation">
    <item name="android:windowEnterAnimation">@anim/slide_down</item>
    <item name="android:windowExitAnimation">@anim/slide_up</item>
</style>

As You can see I declared two animations, here are those codes:

slide_down.xml:

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="0%" android:toYDelta="100%" android:duration="300"/>

slide_up.xml:

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="100%" android:toYDelta="0%" android:duration="300"/>

Now, when calling the dialog.show() method, the dialog just pops up without animation. I've checked my settings and all animations are enabled.

What might I have overseen?

Community
  • 1
  • 1
user2410644
  • 3,861
  • 6
  • 39
  • 59

1 Answers1

0

It seems like I already found the problem:

I just had to link the Dialog to the FinishDialogAnimation instead of the FinishDialog. Looks like that:

dialog.getWindow().getAttributes().windowAnimations = R.style.FinishDialogAnimation;

instead of

dialog.getWindow().getAttributes().windowAnimations = R.style.FinishDialog;
user2410644
  • 3,861
  • 6
  • 39
  • 59