Skip to content

Instantly share code, notes, and snippets.

@jasco
Created October 5, 2014 00:26
Show Gist options
  • Save jasco/e757f1011bb0e62d365f to your computer and use it in GitHub Desktop.
Save jasco/e757f1011bb0e62d365f to your computer and use it in GitHub Desktop.
DialogFragment enter/exit animations
// example courtesy of http://adilatwork.blogspot.com/2012/11/android-dialogfragment-enter-and-exit.html
// file location: src/main/java/com/example/
@Override
public void onStart() {
super.onStart();
// safety check
if (getDialog() == null) {
return;
}
// set the animations to use on showing and hiding the dialog
getDialog().getWindow().setWindowAnimations(
R.style.dialog_animation_fade);
// alternative way of doing it
//getDialog().getWindow().getAttributes().
// windowAnimations = R.style.dialog_animation_fade;
// ... other stuff you want to do in your onStart() method
}
<?xml version="1.0" encoding="utf-8"?>
<!--
courtesy of http://adilatwork.blogspot.com/2012/11/android-dialogfragment-enter-and-exit.html
file location: src/main/res/anim
-->
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="400" />
<?xml version="1.0" encoding="utf-8"?>
<!--
courtesy of http://adilatwork.blogspot.com/2012/11/android-dialogfragment-enter-and-exit.html
file location: src/main/res/anim
-->
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="400" />
<?xml version="1.0" encoding="utf-8"?>
<!--
courtesy of http://adilatwork.blogspot.com/2012/11/android-dialogfragment-enter-and-exit.html
file location: src/main/res/values
-->
<style
name="dialog_animation_fade" >
<item name="android:windowEnterAnimation">@anim/fade_in_dialog</item>
<item name="android:windowExitAnimation">@anim/fade_out_dialog</item>
</style>
@Awoapp
Copy link

Awoapp commented May 28, 2019

Thanks bro.

@Abdallah-Abdelazim
Copy link

Thanks. It works great.

@nicobidone
Copy link

It simple and works great! thanks!

@spartan31
Copy link

It works great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment