chariot423
chariot423

Reputation: 1263

Seems like windowAnimationStyle is being ignored, how to animate custom dialog?

I wish to animate my custom dialog as appearing from a specific point but I am having trouble setting animation to the dialog.

The dialog is a basic RelativeLayout set as layout within a class that extends Dialog.

As some answers here suggested I have tried setting windowAnimations to it like

final myCustomDialog dialog = new myCustomDialog(this); 
dialog.getWindow().getAttributes().windowAnimations = R.style.CustomDialogTheme;

EDIT: setting theme in constructor seems to be working but the animations still don't work

final myCustomDialog dialog = new myCustomDialog(this, R.style.CustomDialogTheme); 

CustomDialogTheme style being

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

<style name="PauseDialogAnimation">
    <item name="android:windowEnterAnimation">@android:anim/fade_in</item>
    <item name="android:windowExitAnimation">@android:anim/fade_out</item>
</style>

It just doesn't work, has no effect. I tried setting the same in android:windowAnimationStyle to the project theme and that worked for the activity.

What am I doing wrong and how do I animate a custom dialog if this doesn't work anymore.

Testing on Android 4.4.4 Paranoid Android with all animations set to 1x and Genymotion simulator for Nexus 5.

Upvotes: 4

Views: 2662

Answers (1)

Carlos J
Carlos J

Reputation: 3045

Try initializing your dialog passing the style on the constructor like this:

final myCustomDialog dialog = new myCustomDialog(this, R.style.CustomDialogTheme);

Upvotes: 2

Related Questions