I have a DialogFragment and i set animation for enter/exit in the onActivityCreated method as below
@Override
public void onActivityCreated(Bundle arg0) {
super.onActivityCreated(arg0);
getDialog().getWindow()
.getAttributes().windowAnimations = R.style.DialogAnimation;
}
my DialogAnimation style files is as follows
<style name="DialogAnimation">
<item name="android:windowEnterAnimation">@android:anim/fade_in</item>
<item name="android:windowExitAnimation">@android:anim/fade_out</item>
</style>
This works for me now...
Now my problem is i want to have two different exit animation one for when the ok button is clicked and one for the cancel button.So what i did was i tried changing the transition just before dismissing but it did'nt work..any solution on how it can be achieved...This is what i tried.
@Override
public void onClick(View v) {
getDialog().getWindow()
.getAttributes().windowAnimations = R.style.DialogAnimation2;
this.dismiss();
}
One simple way to do what you want is to use animation listeners like.
Start animation on your onclick method and dismiss dialog on onAnimationEnd() method.You may have to make snimation objects and start them manually with View's startAnimation(animation) method.
I think the best approach is to call the different animations on Button click. Hence you would have something similar to the below:
If I were you, I would also use correct naming conventions for future reference. For example setting DialogAnimation to OkAnimation and DialogAnimation2 to CancelAnimation.
Home this helps :)
You can set an Up & Down animations for dialog fragment. In 'res/anim' add two files:
// Slide up animation
// Slide dowm animation
// Style
// Inside Dialog Fragment
You should set a theme for your base dialog
let say :-
Then you just need to define the theme that will include your desired animation. In styles.xml add your custom theme:
refer this
You can do it inside your DialogFragment, without changing
You should animate "decor view" in onStart and onClick.
This is the code snipped :
Create Dialog first
Then override onStart method
Here is the result animation
And if you remove scale properties from my code you will get only alpha animation. Exactly as you wanted.
Remove this: